Originally Posted by felgall
If you have it set up as a unique key then the easiest way is to simply try to insert whatever email address they enter. If the insert works then it isn't a duplicate - if the insert fails then you can produce appropriate error handling to advise them of the duplication in the die clause.
While I agree this is the *better* way to go, it is not the simplest way, especially for beginners.
A beginner is likely to have other problems in the INSERT query and won't be able to distinguish between those problems and the duplicate key problem.
If you think you can lead this person by the hand through parsing the error message and figuring out whether the error is a duplicate key or not, then go to it.
I would personally rather have the newbie do it in the two steps, just to isolate the problems better.
I doubt seriously that a newbie will be constructing a website where the difference between one or two queries per page is going to matter. More than likely, the page will only be hit a few times per day, at most, so who cares about a miniscule peformance difference?
But, again, if you are ready to lead this newbie through the parsing of the error message(s), go for it.