Duplicate Insertion Problem !

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
whmemon
Forum Newbie
Posts: 1
Joined: Fri Nov 12, 2010 3:49 am

Duplicate Insertion Problem !

Post 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 ?
User avatar
saltwine
Forum Newbie
Posts: 16
Joined: Tue Nov 09, 2010 7:05 am
Location: London

Re: Duplicate Insertion Problem !

Post 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.
Post Reply