Jump to content

Archived

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

jawinn

Preventing Duplicate Entries in MySQL

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
This is an empty DB.  I will be empting it weekly and eventually daily.  I want to prevent ANY duplicates for a specific column.

Share this post


Link to post
Share on other sites
Then go with a UNIQUE index.

Share this post


Link to post
Share on other sites
[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?

Share this post


Link to post
Share on other sites
You have to modify your script to see if your INSERT failed.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.