Preventing Duplicate Form Submissions to MySQL Database

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
k3ndr4
Forum Newbie
Posts: 2
Joined: Mon Aug 31, 2009 3:41 pm

Preventing Duplicate Form Submissions to MySQL Database

Post 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????
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Preventing Duplicate Form Submissions to MySQL Database

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