Heya,
I'm a Newbie that is a bit confused by the "reload problem" My script updates MySql tables but duplicates the entry. So I've tried to redirect upon successfull update. The redirect works but the duplicate entry
persists. Now stumped..
If someone has a moment I'd deeply appreciate it if you'd look over my script and advise.
Here it is:
<html>
<head>
<title>Search Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {font-family: helvetica, arial, geneva, sans-serif; font-size: x-small}
//-->
</style>
</head>
<body bgcolor="#CCCC99" text="#333399" link="#663366">
<basefont face="Verdana">
</head>
<body>
<?
// includes
include("conf.php");
// form not yet submitted
// display initial form with values pre-filled
if (!$submit)
{
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// generate and execute query
$query = "SELECT id, vintage, mint, grade, location, qty, notes FROM $table WHERE id = '$id'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
// if a result is returned
if (mysql_num_rows($result) > 0)
{
// turn it into an object
$row = mysql_fetch_object($result);
// print form with values pre-filled
?>
<table cellspacing="5" cellpadding="5">
<form action="<? echo $PHP_SELF; ?>" method="POST">
<input type="hidden" name="id" value="<? echo $id; ?>">
<tr>
<td valign="top"><b><font size="-1">Vintage</font></b></td>
<td><input size="50" maxlength="250" type="text" name="vintage" value="<? echo $row->vintage; ?>"></td>
</tr>
<tr>
<td valign="top"><b><font size="-1">Mint</font></b></td>
<td><input size="50" maxlength="250" type="text" name="mint" value="<? echo $row->mint; ?>"></td>
</tr>
<tr>
<td valign="top"><b><font size="-1">Grade</font></b></td>
<td><input size="50" maxlength="250" type="text" name="grade" value="<? echo $row->grade; ?>"></td>
</tr>
<tr>
<td valign="top"><b><font size="-1">Location</font></b></td>
<td><input size="50" maxlength="250" type="text" name="location" value="<? echo $row->location; ?>"></td>
</tr>
<tr>
<td valign="top"><b><font size="-1">Quantity</font></b></td>
<td><input size="50" maxlength="250" type="text" name="qty" value="<? echo $row->qty; ?>"></td>
</tr>
<tr>
<td valign="top"><b><font size="-1">Notes</font></b></td>
<td><textarea name="notes" cols="40" rows="10"><? echo $row->notes; ?></textarea></td>
</tr>
<tr>
<td colspan=2><input type="Submit" name="submit" value="Update"></td>
</tr>
</form>
</table>
<?
}
// no result returned
// print graceful error message
else
{
echo "<font size=-1>That record could not be located in our database.</font><br>";
echo "<font size=-1> <a href=index.php>main menu</a>.</font>";
}
}
// form submitted
// start processing it
else
{
// set up error list array
$errorList = array();
$count = 0;
// validate text input fields
if (!$vintage) { $errorList[$count] = "Invalid entry: Vintage"; $count++; }
if (!$mint) { $errorList[$count] = "Invalid entry: Mint"; $count++; }
if (!$grade) { $errorList[$count] = "Invalid entry: Grade"; $count++; }
if (!$location) { $errorList[$count] = "Invalid entry: Location"; $count++; }
if (!$qty) { $errorList[$count] = "Invalid entry: Quantity"; $count++; }
if (!$notes) { $errorList[$count] = "Invalid entry: Notes"; $count++; }
// check for errors
// if none found...
if (sizeof($errorList) == 0)
{
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// generate and execute query
$query = "UPDATE pennies SET vintage = '$vintage', mint = '$mint', grade = '$grade',
location = '$location', qty = '$qty', notes = '$notes' WHERE id = '$id'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
// print result
echo "<font size=-1>Update successful. <p><a href=index.php>Go back to the main menu</a>.</font></p>";
// close database connection
mysql_close($connection);
}
else
{
// errors occurred
// print as list
echo "<font size=-1>The following errors were encountered: <br>";
echo "<ul>";
for ($x=0; $x<sizeof($errorList); $x++)
{
echo "<li>$errorList[$x]";
}
echo "</ul></font>";
}
}
?>
</body>
</html>
:eek: