Hi all,
I've created a support ticket system for users that have questions while on my site. The questions are stored inside a database. On my admin page, I access this information, and show it to the screen, where I can then answer the question. It all works great, except one problem.
The unanswered question that displays on the top of the page is supposed to be replaced with a new question upon hitting Submit. Also, the number of support tickets left is supposed to update (where it says Number of Tickets🙂
What do I need to change to my code to make it update the new question and new total of tickets when I hit submit?
Thanks.
<?php
session_start();
include_once('../inc/nav.php');
$submit = $_POST['submit'];
if(isset($_SESSION['username'])){
include_once('../inc/connect.php');
$supportsql = "SELECT * FROM `support` WHERE `answered`='no' ORDER BY `date` DESC";
$result = mysql_query($supportsql);
$row = mysql_fetch_assoc($result);
$num = mysql_num_rows($result);
$username = $row['username'];
$i = 0;
while ($i < $num) {
$user = mysql_result($result,$i,"username");
$message = mysql_result($result,$i,"message");
$number = mysql_result($result,$i,"number");
// echo "<br /><div align='center' id='question'><strong>".ucfirst($user)."<br /></strong>".$message."<br /></div>";
$i++;
}
echo "<br /><center>Number of Tickets: ".$num."</center>";
echo "<br /><div align='center' id='question'><strong>".ucfirst($user)."<br /></strong>".$message."<br /></div>";
// Find Their Email Address
$emailsql = "SELECT email FROM users WHERE username='$username'";
$emailresult = mysql_query($emailsql);
$erow = mysql_fetch_assoc($emailresult);
$email = $erow['email'];
if ($submit){
$answer = $_POST['answer'];
$signature = "If you have anymore questions, feel free to ask! \nThank You,\n<html><a href='http://www.daobux.com'>Daobux Team</a></html>";
$usermail = ucfirst($username);
mail("$email", "Reply: $message", "
Hello $usermail,\n
$answer\n
$signature
");
$answeredsql = "UPDATE `support` SET `answered`='yes' WHERE number='$number'";
mysql_query($answeredsql);
}
}
?>
<html>
<head>
<title>Support Tickets</title>
<style>
#question{
width: 500px;
background-color: #cccccc;
border-style: solid;
border-width: 2px;
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body OnLoad="document.supportticket.answer.focus();">
<center>
<h1>Answer Queries:</h1>
<form name="supportticket" action="supportticket.php" method="POST">
<textarea rows="8" cols="50" name="answer"></textarea><br />
<input type="submit" name="submit" value="Submit">
</form>
<br />
<?php echo $error; ?>
</center>
</body>
</html>