Hi guys.
Im having a problem getting my head around why my form keeps posting if i refresh my page.
The first time i go to my page (onefile.php), it is fine.
But as soon as I enter a value in a textbox and submit it (which adds one record to a database), and then refresh the page, I get....
In Internet Explorer....
"Internet Explorer needs to resend the information............"
and in Firefox....
"The page you are trying to view contains POSTDATA. If you resend the data, any action the form carried out will be repeated)...
Can someone please examine my script, and see:
1) If my code is missing anything
2) What should I do to my code to factor in users refreshing the page?
Is it normal to factor in this user action, and if so, what normally is good practice?
Any help greatly appreciated.
--------------------------
----------
----------
----------
----------
----------
----------
----------
---- onefile.php
<html>
<!-- Code Start:
---------------- -->
<!-- INSERT A NEW AREA:
----------------------- -->
<form action="onefile.php" method="POST">
Insert a new area: <input type="text" name="newarea">
<input type="submit" name="submit" value="Go">
</form>
<!-- DISPLAY ALL RECORDS:
----------------------- -->
<form action="onefile.php" method="POST">
Display all records: <input type="submit" name="displayall" value="All">
</form>
</html>
<?php
// Include our connection information to connect to mysql database
//------------------------
----------
----------
----------
----------
include("connectioninfo.ph
p");
//Insert a new area into the table called areas_are
//------------------------
----------
----------
-----
/*
mysql_query("INSERT INTO areas_are (name_are) VALUES('$_POST[newarea]') ") or die(mysql_error());
echo "Data Inserted!";
print "<br>";
*/
/*
if(!empty($_POST[newarea])
) {
$sql="INSERT INTO areas_are (name_are) VALUES ('$_POST[newarea]')";
echo "1 record added";
print "<br>";
} else {
print "Please submit a value. A blank value is not allowed \n";
}
*/
// First, check to see which button the user clicked on
if($_POST['displayall']) {
echo "User clicked on the All button <br />";
$sQuery = "SELECT name_are FROM areas_are";
$refResult = mysql_query($sQuery);
while($aRow = mysql_fetch_array($refResu
lt, MYSQL_ASSOC))
{
echo "Name: $aRow[name_are]<br />";
}
}
elseif ($_POST['submit']) {
echo "User clicked on the Go button <br />";
if(!empty($_POST[newarea])
) {
$sql="INSERT INTO areas_are (name_are) VALUES ('$_POST[newarea]')";
mysql_query($sql) or die(mysql_error());
echo "1 record added";
print "<br>";
} else {
print "Please submit a value. A blank value is not allowed \n";
}
}
?>
--------------------------
----------
----------
----------
----------
----------
-----