EchoFool Posted December 1, 2009 Share Posted December 1, 2009 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/183629-prevent-double-entry/ Share on other sites More sharing options...
Psycho Posted December 1, 2009 Share Posted December 1, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/183629-prevent-double-entry/#findComment-969214 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.