Jump to content

Prevent double entry


EchoFool

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.