Really without being confirmed with your problem, i have made some slight changes here in your code here. I hope this will work for you.
PHP Code:
<?php
$dbhost = '***';
$dbuser = '***';
$dbpass = '***';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'jokedb';
mysql_select_db($dbname) or die ("hmm an error with database!!<BR>" . mysql_error());
if (isset($_POST['name'])){
$name = $_POST['name'];
$email = $_POST['email'];
$id = $_POST['id'];
$sql = "UPDATE author SET name='$name',email='$email' WHERE id='$id'";
if (@mysql_query($sql)){
echo '<p>New author updated</p>';
header("Location:" . $_SERVER['HTTP_REFERER']);
exit();
} else {
echo '<p> error updating new author: ' . mysql_error() . '<p/>';
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<p><a href="authors.php">Return to authors list</a></p>
<?php
$id = $_GET['id'];
$author = @mysql_query("SELECT name, email FROM author WHERE id='$id'");
if (!$author) {
exit('<p>Error fetching author details; ' . mysql_error() . '</p>');
}
$author = mysql_fetch_array($author);
$name = $author['name'];
$email = $author['email'];
$name = htmlspecialchars($name);
$email = htmlspecialchars($email);
?>
<form action="<?php echo $PHP_SELF; ?>" method="post">
<p>Edit an author</p>
<label> Name <input type="text" name="name" value="<?php echo $name; ?>" /></label><br />
<label> Email <input type="text" name="email" value="<?php echo $email; ?>"/></label><br />
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
When do you want to refresh your page?
Bookmarks