geroido Posted August 28, 2008 Share Posted August 28, 2008 Hi I have a continuous problem with database insertion. I wonder if you have any advice. For example, if I allow a user to fill out a booking form and then insert the record in the database it all works well. I then send the user a message after insert (all happening on the same page) thanking them for their booking. Now the problem I have is if the user right clicks on the webpage and refreshes, it inserts the record again. I don't want this. Is their a way to prevent this. Link to comment https://forums.phpfreaks.com/topic/121742-on-duplicate-sql-problem/ Share on other sites More sharing options...
revraz Posted August 28, 2008 Share Posted August 28, 2008 Check to see if they exist before inserting Link to comment https://forums.phpfreaks.com/topic/121742-on-duplicate-sql-problem/#findComment-628041 Share on other sites More sharing options...
geroido Posted August 28, 2008 Author Share Posted August 28, 2008 I'm not sure how to do that. Once the record is inserted, the booking number is an auto increment. How would I know what the booking number is so that I can check it. This happens in the database unseen to me. Link to comment https://forums.phpfreaks.com/topic/121742-on-duplicate-sql-problem/#findComment-628062 Share on other sites More sharing options...
BlueSkyIS Posted August 28, 2008 Share Posted August 28, 2008 i typically use a session variable to indicate that the visitor has completed an action and that action should not be re-inserted unless the visitor starts over from the beginning. if the session var is 'completed' and the user attempts a refresh, i redirect them to the start page. Link to comment https://forums.phpfreaks.com/topic/121742-on-duplicate-sql-problem/#findComment-628067 Share on other sites More sharing options...
revraz Posted August 28, 2008 Share Posted August 28, 2008 Well one thing that would help is redirect them away after they submit to a different thank you page. Link to comment https://forums.phpfreaks.com/topic/121742-on-duplicate-sql-problem/#findComment-628076 Share on other sites More sharing options...
BlueSkyIS Posted August 28, 2008 Share Posted August 28, 2008 that would prevent a certain percentage of re-inserts, but not all of them. using sessions will stop all of them. Link to comment https://forums.phpfreaks.com/topic/121742-on-duplicate-sql-problem/#findComment-628084 Share on other sites More sharing options...
geroido Posted August 28, 2008 Author Share Posted August 28, 2008 Thanks all I'll test out those suggestions now Link to comment https://forums.phpfreaks.com/topic/121742-on-duplicate-sql-problem/#findComment-628086 Share on other sites More sharing options...
BlueSkyIS Posted August 28, 2008 Share Posted August 28, 2008 you may also want to use some code to try to prevent browser caching of the form page, though i haven't had to use it since i started using sessions as described above. // Try to prevent caching header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); Link to comment https://forums.phpfreaks.com/topic/121742-on-duplicate-sql-problem/#findComment-628087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.