Click to See Complete Forum and Search --> : POSTDATA - page Refreshing


LogicOpinion
11-15-2007, 06:49 AM
hello again..

i need some advice about problem described below.

so:

i have form where i enter some text

here is the form

<form action="index.php?p=itm1" method="post">
<table height="100" border="0" cellpadding="0" cellspacing="0">
<TR><TD colspan="3"><i>some text</i></TD></TR>
<TR>
<TD align="center">enter new name&nbsp;:&nbsp;</TD>
<TD align="center"><input type="text" name="item"></TD>
<TD align="center"><input type="submit" value="add"></TD>
</TR>
</table>
</form>

after this text inserted into form as u see is sent to php file called itm1.php

here is the code of that page



<?php
include("includes/vars.php");

$item = $_POST['item'];

if ($_POST['item']=$item)

{

mysql_connect("$hostname", "$username", "$password") or die(mysql_error());
mysql_select_db("$db") or die(mysql_error());
mysql_query("CREATE TABLE IF NOT EXISTS menu(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
item VARCHAR(300)) ") or die(mysql_error());
mysql_query("INSERT INTO menu (item)
VALUES('$item')") or die(mysql_error());


print "<br />";
echo "&nbsp;&nbsp;new item named <b>$item</b> has been added";
print "<br />";
}

else

{

echo "error.. error description";

}


?>


if "if" statmant is true it adds new item to db and echos "new item has been added" so everything goes fine.. but

when i refresh the page post data is added to database again..

how can i avoid this? i want if someone refreshes the page ... to do something else but not to add the same item again to database.

thanks

felgall
11-15-2007, 07:59 PM
You need to test if the data is a duplicate of the last entry that was added before allowing it to be added again.

LogicOpinion
11-17-2007, 03:37 AM
Could you give (show) me some example of testing that ?

thanks