Jump to content

Prevent Double entry of data into MySQL


SA Rob

Recommended Posts

Hi Folks,I have a form which sends data to MySQL.However if a person submits the from twice then their will be a double entry for an event and I would like to prevent this from happening.If there is any person that can help with script in this regard - I would appreciate it.RegardsRob

Link to comment
Share on other sites

You need to identify what constitute as "unique" and mark that value as such in your database.If, for example, the combination of a place and time maps to an "event", make that a primary key.Once you do that, your DB will automatically fail to insert duplicate entries, and PHP could then do some error handling if this occurs.

Link to comment
Share on other sites

You could also use the "REPLACE INTO ..." SQL syntax. It works the same as "INSERT INTO" except it replaces rows with duplicate data.
Hi Folks,Thanks fopr the replies.The best way to do this I think is a combination of using the date of birth and cell numbers.This is unique as the entrants to the various tournaments have to enter this information and it is unique to all.In trying to keep it simple is there not a way that once the submit button is pressed that information becomes unique and thus it cannot be resubmitted with exactly the same information.Sorry for all the questions but my knowledge is not good at all.RegardsRob
Link to comment
Share on other sites

you would want to perform a check of some sort when the form is submitted to PHP. I think a good way to check is to have them submit their email address with their information, and inform them it will be your primary source of contact with them, and most people only have one personal email address. This would also provide a decent way of checking against the database. You could then do a SELECT * from the table, and have it look up the records by email address. If it returns a result set, then you know it already exists and you can re-direct the user to another page informing them that their information already exists, or something like that. If not, then you can carry out the INSERT as usual. There's probably a way to do this all in one query though. Some of these links might lead to those solutions.this one features a particular mod from our site! :)http://www.designerstalk.com/forums/progra...duplicates.htmlhttp://www.tutorialspoint.com/mysql/mysql-...-duplicates.htm

Link to comment
Share on other sites

Hi Folks,Thanks fopr the replies.The best way to do this I think is a combination of using the date of birth and cell numbers.This is unique as the entrants to the various tournaments have to enter this information and it is unique to all.In trying to keep it simple is there not a way that once the submit button is pressed that information becomes unique and thus it cannot be resubmitted with exactly the same information.Sorry for all the questions but my knowledge is not good at all.RegardsRob
i think you should use UNIQUE constraint in cell number and dateofbirth..if the data already exist it will raise a mysql error..you can ctach the error number and do error handling based on error number
Link to comment
Share on other sites

i think you should use UNIQUE constraint in cell number and dateofbirth..if the data already exist it will raise a mysql error..you can ctach the error number and do error handling based on error number
That reply made me search the MySQL manual, just to make sure, and... yeah... I only now realize the UNIQUE constaint can, similarly to primary keys, be applied over to a range of columns. Up until now, I thought it must be applied separately on each column... something new every day...Sctratch what I said earlier than, and if the data isn't already a primary key, make it UNIQUE instead.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...