-
I have a simple form that has one field:
email
And my forms action is: email.php
In email.php, i just insert the email address to a table called:
site
and a database called:
petesmc_misc
What i want to know is, using PHP how can i check for a duplicate value in the table before trying to insert. If i insert then the user would get the message:
You could not be added: Duplicate value, "test@test.com" for Key 1
Is there a way i can check first then say if it is duplicate?
Thanx
-
Pete wouldn't it be better to not have the email field as a unique key, instead make auto-increment id field then when you want to access the list of emails you can use SELECT DISTINCT email from site; Instead of running two queries to see if they are already in there? But if you want the long way
$result = mysql_query("SELECT email from site where email = '$email'");
if (mysql_num_rows($result) > 0) {
print "Email already in db";
}
else {
//insert query here
}
-