Jump to content

On duplicate sql problem


geroido

Recommended Posts

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

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.

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");	

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.