Jump to content

Recommended Posts

Hey,

 

I have a form for purchasing (adding to kart), and occasionally for what ever reason - users accidentally submit twice. Either from accidently hitting refresh or pressing back buttons etc.

 

How would you prevent a double entry - i tried to "unset" the _POST variables from the form - meaning is they did it a second time without actually going back to the form to hit submit then nothing occurs but they don't unset.

 

For example my ending script has :

 

// update mySQL
Echo 'Item has been added'; 

 

Now if a user refreshes that process page it adds it again but i want to prevent this by unsetting the POST variables... how would you do it ?

Link to comment
https://forums.phpfreaks.com/topic/183629-prevent-double-entry/
Share on other sites

I typically prevent double submissions by doing a header redirect right after I process the POST data. Once the redirect occurs there is no POST data, so the user can refresh all they want and there won't be a double submission.

 

However, the user using the back button is a different story. In that situation I would create the form with a hidden field with some random value. When the form is submitted I would save that random value with the data. Then if the user hits the back button and resubmits I can check that the random value already exists and not allow the resubmission.

Link to comment
https://forums.phpfreaks.com/topic/183629-prevent-double-entry/#findComment-969214
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.