Hi everyone.
I use a simple form to edit the authors of jokes in a database. I am able to update the database, but then when the page loads after hitting submit, it gives me the previous data. Please find the code I have used:
<html>
<head>
<title>Edit Authors</title>
</head>
<body>
<?
$dbcnx=@mysql_connect("localhost", "root", "");
mysql_select_db("jokesdb");
$authors=mysql_query("SELECT * FROM Authors WHERE ID= '$id'");
if(!$authors){
echo("<P>Error retrieving authors from database!<br>".
"Error: ".mysql_error());
exit();
}
while($author=mysql_fetch_array($authors)){
$id=$author["ID"];
$name=$author["Name"];
$email=$author["Email"];
}
?>
<form method="post" action="">
<p><strong>Edit the Author:</strong></p>
<p>Name:
<input name="name" type="text" value="<?php echo($name);?>" size="20" maxlength="100">
</p>
<p>Email:
<input name="email" type="text" value="<?php echo($email);?>" size="20" maxlength="100">
<input name="id" type="hidden" id="id" value="<?php echo($id);?>">
</p>
<p>
<input type="submit" name="Submit" value="Update">
</p>
</form>
<?
if ($Submit):
$id=$_POST['id'];
$name=$_POST['name'];
$email=$_POST['email'];
$sql="UPDATE authors SET Name='$name', Email='$email' WHERE ID='$id'";
if(mysql_query($sql))
{
echo("<p><font color='#0099ff'><b>Record Successfully Updated!</font></b></p>");
echo("<a href='authors.php?id=$id'>Return to Authors List</a>");
}
else
{
echo("<p><font color='#ff0000'><b>Error performing update: ".
mysql_error()."</font></b></p>");
}
endif;
?>
</body>
</html>
I want to refresh the page automatically with the form holding the newly submitted data from the database after I submit the changes. Please help!