Page 1 of 1

Duplicate Insertion Problem !

Posted: Fri Nov 12, 2010 4:02 am
by whmemon
Hi Friends !

I need to discuss a problem with you.
When we fill a customer info form, and redirect to other page. but go back by browser's back button and resubmit the form.
In this case duplicate data is inserted. Or when we refresh a page multiple data is inserted, so HOW TO AVOID this terrible problem ?

Re: Duplicate Insertion Problem !

Posted: Fri Nov 12, 2010 5:12 am
by saltwine
Hi whmemon


There are a few ways to get around this problem. One I've successfully used before was to create two extra fields in the database table you are updating: ip and timestamp.

On processing form submissions, store the user's IP, using $_SERVER['REMOTE_ADDR'], and the current timestamp, using the time() function, with the information you are capturing.

Then update your code to run a check to pull rows from that database table where the current IP has made a submission in, say, the last 60 seconds. If your check returns a row, you're most likely dealing with a duplicate submission, so don't process the request.