SA Rob Posted January 24, 2011 Share Posted January 24, 2011 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 More sharing options...
boen_robot Posted January 24, 2011 Share Posted January 24, 2011 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 More sharing options...
Fmdpa Posted January 24, 2011 Share Posted January 24, 2011 You could also use the "REPLACE INTO ..." SQL syntax. It works the same as "INSERT INTO" except it replaces rows with duplicate data. Link to comment Share on other sites More sharing options...
SA Rob Posted January 24, 2011 Author Share Posted January 24, 2011 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 More sharing options...
thescientist Posted January 24, 2011 Share Posted January 24, 2011 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 More sharing options...
birbal Posted January 25, 2011 Share Posted January 25, 2011 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.RegardsRobi 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 More sharing options...
boen_robot Posted January 25, 2011 Share Posted January 25, 2011 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 numberThat 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.