Page 1 of 1

Data doubling in database on F5

Posted: Sun Feb 08, 2009 10:42 pm
by itp
I have seen this problem in other sites and have come across occationally in my work. Say you have a web page where user enters information and clicks button to submit. If user presses then presses F5 or backs up and clicks submit again information will be doubled in database, if no validation is done to detect duplicate records, or duplicate keys. However, sometimes there is no unique key entered by the user or key is just a sequential number (like a comment on a blog or an oline order for a magazine). In this case it is hard to determine what is an invalid duplicate entry.

One way I have been avoiding upwanted duplicates if by generating a random number when users enters HTML form for the first time or after database update. I pass this number from page to page on as a hidden value on the form submit button. I also put this value in a $_SESSION variable. When it is time to update the database, I check that $_SESSION value = get/post value. If equal, program will insert data to database, show confirmation screen and generate new random number. If not equal, program will give error message, generate a new random number and show new blank form.

Code: Select all

$_SESSION['guestAddedToken'] = $this->fnGenerateToken();
I wonder how other people handle this issue.

Re: Data doubling in database on F5

Posted: Sun Feb 08, 2009 10:52 pm
by Benjamin
Just send a header redirect to the landing page.

Re: Data doubling in database on F5

Posted: Mon Feb 09, 2009 9:19 pm
by itp
Gee why didn't I think of that? I guess that would work for POSTs, but not for GETs.
Also this would not prevent someone from hitting back button & submit a second time.