Jump to content

Refresh information on submit


Smudly

Recommended Posts

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>

Link to comment
Share on other sites

Thanks for replying. I tried doing this previously, and again right now. But nothing seems to be working. I tried placing it in different places, and moving different pieces of code around. But to no avail, any other ideas?

Link to comment
Share on other sites

you should have if(isset($_POST['submit'])) not if ($submit) where $submit = $_POST['submit'].

also, you should store all the information you're echoing in the header into a variable and echo it in the HTML body.

<?php
session_start();

include_once('../inc/nav.php');

if(isset($_SESSION['username'])){  

include_once('../inc/connect.php');

if (isset($_POST['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);



}

$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'];

}

?>

<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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.