Page 1 of 1
catching refreash
Posted: Thu Jan 15, 2004 1:41 am
by mike123456789
Hi, i'm fairly new to php and having a problem when the refresh button is clicked. I have a form that calls itself when the submit button is hit. It insterts fine however when i click refresh, the insert command is called again resulting in a duplicate key errror. Is there any php commands that will catch the refresh button to stop the instert query from begin exec again?
Thanks!!!
Posted: Thu Jan 15, 2004 2:04 am
by microthick
Not that I know of.
But what I do is when the page is submitted and after I've processed the form, I redirect the user back to the same page. The redirect basically removes the POST data so that refreshes can occur painlessly.
Posted: Thu Jan 15, 2004 11:59 am
by McGruff
If your db structure already prevents a duplicate row you're halfway there.
Before carrying out the INSERT, check for an existing row with the same value in the unique col as the one you are about to try to insert.
Posted: Thu Jan 15, 2004 12:30 pm
by timhortons
McGruff wrote:If your db structure already prevents a duplicate row you're halfway there.
Before carrying out the INSERT, check for an existing row with the same value in the unique col as the one you are about to try to insert.
Thats what I'd suggest.
As well, I'm not sure how well this works, or if it does, I tried once but I cant remember what happened, but at the bottom of all my form processing, I manually set the POST field to null, or ''... like
$_POST = null;
[edit] Opps, yeah, the null thing wont work, hehe, it just occured to me that when you refresh, you re send the data... it over rides setting it to null... but, yeah, you can prevent multiple inserts by making sure the stuff your inserting doesnt have the same key as something already in the table [/edit]
Posted: Thu Jan 15, 2004 2:49 pm
by mike123456789
Thanks for all your suggestions and tip everyone!
I will just check if the record exsits first.
Thanks!