Page 1 of 1

Preventing Duplicate Form Submissions to MySQL Database

Posted: Sun Sep 06, 2009 6:13 pm
by k3ndr4
Hello. I have a form that submits information to a backend SQL database using AJAX/PHP. The form consists of two dropdown boxes. The value of each dropdown box and the username of the logged in user are inserted into a SQL table upon submitting the form. How do I prevent the user from creating duplicate submissions?

For example, say the user chooses the make of a car from dropdown #1, and the model of a car from dropdown #2. The values that get written to the table are:

Ford, Taurus, Mike

But the problem is that Mike can resubmit the form and add another Ford model. The next time he submits, these values are written to the table:

Ford, Focus, Mike

How can I set up the PHP to check if Mike has already submitted a Ford and prompt him to overwrite the record so there are no duplicate Ford submissions for user Mike????

Re: Preventing Duplicate Form Submissions to MySQL Database

Posted: Mon Sep 07, 2009 12:38 am
by Eric!
k3ndr4 wrote:How can I set up the PHP to check if Mike has already submitted a Ford and prompt him to overwrite the record so there are no duplicate Ford submissions for user Mike????
I think you answered your own question. Just query the database before adding data to make sure it isn't a duplicate. You could also time stamp the entries and see if the submission was made within, say 2 minutes of the last one and if it is a duplicate to prompt the user.