My code adds data to the table successfully on submit. However, it won't display the newly added data (pulled out with a mySQL statement etc) until i either refresh the page or go to another page and come back.
I can solve the problem by posting to another page with a re-direct back but this is not preferable to posting the data to itself.
Has anyone had this problem before? Please help, my code is below:
Code: Select all
$result = mysql_query("SELECT * FROM gigdates");
if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>");
exit();
}
/* Add new gig if submitted */
if (isset($_POST['submitgig'])) {
$gigtitle = $_POST['gigtitle'];
$gigdate = $_POST['gigdate'];
$sql = "INSERT INTO gigdates SET " .
"gigtitle='$gigtitle', " .
"gigdate='$gigdate'";
if (mysql_query($sql)) {
echo("<p>The gig has been added.</p>");
} else {
echo("<p>Error adding adding gig: " .
mysql_error() . "</p>");
}
}
?>
<ul>
<?php
while ( $row = mysql_fetch_array($result) ) {
echo("<li><a href= \" ../news.php \" >" . $row["gigtitle"] . "</a></li>");
echo("<li>" . $row["gigdate"] . "</li>");
}
?>
</ul>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<p>Input where you're playing (eg: The Vine, Leeds):</p>
<input type="text" name="gigtitle"></input>
<p>Input the date of where you're playing (eg:17th August 2007):</p>
<input type="text" name="gigdate"></input>
<p><input type="submit" name="submitgig" value="submit"></p>
</form>