Hello,
I have a PHP script which collects asset information from my company. When the script is run and someone enters the information they press Submit and all works ok. It brings up another page saying that the information was successfully entered. However if you now press refresh, it still only displays the successful page, and then enteres the information twice. The only way to go back and enter the data is to close the browser and then reopen it and type the link again. then it will come up with the data entry page. Can anyone tell me how I can make it so that when the user refreshes the page, it allows them to enter more information.
Here is the script.
<html>
<head>
<title>Asset Register</title>
<BODY>
<?php
if ( !isset( $_POST['submit'] ) )
{
echo <<< EOF
<FORM ACTION="{$_SERVER['PHP_SELF']}" METHOD="post">
<center><TABLE width = "500">
<TR>
<TD ALIGN="LEFT" VALIGN="TOP" COLSPAN=2>
<h1>EMEA Asset Register</h1><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
Please enter the required(*) information so that we can keep a record of your data. <br><br>
<br>
Please DO NOT ENTER ANY PRINTERS ETC, ONLY LAPTOPS and Pc's <BR>
<tr>
<td colspan="2" valign="middle" bgcolor="#0066cc"><font color="white"><b><img src="http://localhost/meet/images/spacer.gif" height="10" width="10"><br>
<img src="http://localhost/meet/images/spacer.gif" height="2" width="20">Your Details</b></font></td>
</tr></TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP" COLSPAN=1>
<div align="right">*Full Name:</div></TD>
<TD ALIGN="LEFT" VALIGN="TOP" COLSPAN=1>
<INPUT TYPE=TEXT NAME="fullname" VALUE="" SIZE="27" MAXLENGTH="30"> </TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP" COLSPAN=1>
<div align="right">*Location:</div></TD>
<TD ALIGN="LEFT" VALIGN="TOP" COLSPAN=1>
<INPUT TYPE=TEXT NAME="location" VALUE="" SIZE="27" MAXLENGTH="80"> </TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP" COLSPAN=1>
<div align="right">*Machine Make:</div></TD>
<TD ALIGN="LEFT" VALIGN="TOP" COLSPAN=1>
<INPUT TYPE=TEXT NAME="machinemake" VALUE="" SIZE="27" MAXLENGTH="40"> </TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP" COLSPAN=1>
<div align="right">*Machine Type:</div></TD>
<TD ALIGN="LEFT" VALIGN="TOP" COLSPAN=1>
<INPUT TYPE=TEXT NAME="machinetype" VALUE="" SIZE="27" MAXLENGTH="100"> </TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP" COLSPAN=1>
<div align="right">*Asset Number:</div></TD>
<TD ALIGN="LEFT" VALIGN="TOP" COLSPAN=1>
<INPUT TYPE=TEXT NAME="assetnum" VALUE="" SIZE="27" MAXLENGTH="40"> </TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP" COLSPAN=1>
<div align="right">*Serial Number:</div></TD>
<TD ALIGN="LEFT" VALIGN="TOP" COLSPAN=1>
<INPUT TYPE=TEXT NAME="serialnum" VALUE="" SIZE="27" MAXLENGTH="40"> </TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP" COLSPAN=2>
<br>
<tr>
<TD ALIGN="LEFT" VALIGN="TOP" COLSPAN=2>
<input type="submit" name="submit" value="Submit!"> <INPUT TYPE="reset" value ="Reset">
</FORM></center>
EOF;
}
else
{
$ipaddress = getenv("REMOTE_ADDR" );
$fullname = trim( $_POST['fullname'] );
$location = trim( $_POST['location'] );
$machinetype = trim( $_POST['machinetype'] );
$machinemake = trim( $_POST['machinemake'] );
$assetnum = trim( $_POST['assetnum'] );
$serialnum = trim( $_POST['serialnum'] );
if(!$_POST['fullname']) //<----
{ $error_message .= "Full Name cannot be BLANK </BR> ";
}
if(!$_POST['location']) // <----
{ $error_message .= "Location cannot be BLANK. </BR> ";
}
if(!$_POST['machinetype']) // <----
{ $error_message .= "Machine Type cannot be BLANK. </BR>";
}
if(!$_POST['machinemake']) // <----
{ $error_message .= "Machine Make cannot be BLANK</BR> ";
}
if(!$_POST['assetnum']) // <----
{ $error_message .= "Asset Number cannot be BLANK. </BR> ";
}
if(!$_POST['serialnum']) // <----
{ $error_message .= "Serial Number cannot be BLANK </BR> ";
}
$cnx = mysql_connect("localhost", "root", "" ) or die("connection error" );
mysql_select_db("emeaasset", $cnx) or die("DB error" );
$query = "INSERT into asset VALUES ('$fullname', '$location', '$machinetype', '$machinemake', '$assetnum', '$serialnum')";
if(!$error_message) {
mysql_query($query) or die("There has been an error with executing the query. Your informarion has NOT been saved. Please contact the system administrator for further informartion the error is - query error" );
echo "<B><h3>Thankyou for submitting your information. It has been recorded in the database.</h3></B>";
}
else
echo $error_message;
}
?>
</BODY>
</HTML>