catching refreash

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mike123456789
Forum Newbie
Posts: 2
Joined: Thu Jan 15, 2004 1:41 am

catching refreash

Post 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!!!
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post 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.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
timhortons
Forum Commoner
Posts: 29
Joined: Thu Jan 15, 2004 11:48 am
Location: Calgary, AB, Canada

Post 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]
mike123456789
Forum Newbie
Posts: 2
Joined: Thu Jan 15, 2004 1:41 am

Post by mike123456789 »

Thanks for all your suggestions and tip everyone!
I will just check if the record exsits first.

Thanks!
Post Reply