Refresh information on submit

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smudly
Forum Commoner
Posts: 71
Joined: Wed Jun 09, 2010 10:09 pm

Refresh information on submit

Post by Smudly »

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.

Code: Select all

<?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>
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: Refresh information on submit

Post by jraede »

Is the code you provided from supportticket.php? Regardless, if you have it set up right you would post/handle the data either on a separate page or on the top of the same page, and then get all the info to display (open tickets, etc). The newly posted data will display on the page if you order the processes correctly.
Post Reply