jawinn Posted October 3, 2006 Share Posted October 3, 2006 I have a web form that dumps form data into a DB. One of the fields is for email address. I would really like the form to kick back an error message if an email address is used that is already in the DB. My DB only has one table. What would the code be for that?Thanks in advance,J Link to comment https://forums.phpfreaks.com/topic/22908-preventing-duplicate-entries-in-mysql/ Share on other sites More sharing options...
fenway Posted October 3, 2006 Share Posted October 3, 2006 There are lots of ways to handle this, depending on whether you can't have duplicates ever, or just do want to add new ones. You can simply query the table before and see if another matching entry is found, or you can strictly enforce it with an index. Link to comment https://forums.phpfreaks.com/topic/22908-preventing-duplicate-entries-in-mysql/#findComment-103377 Share on other sites More sharing options...
jawinn Posted October 3, 2006 Author Share Posted October 3, 2006 This is an empty DB. I will be empting it weekly and eventually daily. I want to prevent ANY duplicates for a specific column. Link to comment https://forums.phpfreaks.com/topic/22908-preventing-duplicate-entries-in-mysql/#findComment-103390 Share on other sites More sharing options...
fenway Posted October 3, 2006 Share Posted October 3, 2006 Then go with a UNIQUE index. Link to comment https://forums.phpfreaks.com/topic/22908-preventing-duplicate-entries-in-mysql/#findComment-103406 Share on other sites More sharing options...
jawinn Posted October 3, 2006 Author Share Posted October 3, 2006 [quote author=fenway link=topic=110407.msg446343#msg446343 date=1159910890]Then go with a UNIQUE index.[/quote]How do I add that to my script? Link to comment https://forums.phpfreaks.com/topic/22908-preventing-duplicate-entries-in-mysql/#findComment-103410 Share on other sites More sharing options...
fenway Posted October 4, 2006 Share Posted October 4, 2006 You have to modify your script to see if your INSERT failed. Link to comment https://forums.phpfreaks.com/topic/22908-preventing-duplicate-entries-in-mysql/#findComment-103893 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.