Page 1 of 1

stop resubmiting of post data when refresh

Posted: Wed Dec 17, 2003 8:33 am
by hibbeac1
I have an application that is in PHP and MySQL. When a button is pressed it will perform and action on the database either to add, edit or delete data that a user has entered. When adding data after the refresh button is pressed at the top of the page the data is added again, so you get another occurence of the data. Is there anyway of stopping this happening.

Posted: Wed Dec 17, 2003 9:29 am
by aquila125
put a hidden field in the form with a random number in it.. add this number to the database, if it already exists (and the data is the same), don't save the data...

You could just check the data and skip the random number ofcourse.. (perhaps at some time you would want to add the same data twice..)

Posted: Wed Dec 17, 2003 4:02 pm
by Paddy
Or redirect it to itself to get rid of the post data. Add

header("Location: thepage.php");

After the db manipulation and before any html.