I have a mysql database that includes the fields first_name, last_name, email.
I have an input form to enter in the above information. If the e-mail address already exists, then I have a message page that lets the user know this and display the first and last name that already exists. Duplicate first and last names are OK.
The code below is not catching the duplicate e-mail address that is entered in the input form. How do I get it to work?
$result = mysql_query("SELECT * FROM mail_list_db where '$email_address' = email") or die(mysql_error());
$count = mysql_num_rows($result);
echo "Count = " . $count . " " . $FName . " " . $LName; //<== Always display zero instead of one if the e-mail address already exists. First and last names display correctly.
if($count == 0) {
// save the information to the database
$query="INSERT INTO mail_list_db (first_name, last_name, email, id_key, remove, date_added, notes)
VALUES('$FName', '$LName', '$email_address', '$id', '$remove', '$time_now', '$notes')";
mysql_query($query) or die ("Error in query: $query");
// Now go back to the input form
print "<meta http-equiv=\"refresh\" content=\"0;URL=add.php\">";
}
else {
// Display duplicate message along with first nad last name of the DB record.
}
If I change the first line to use either the first or last name, the count is greater than zero if the first or last name already exists.
Example:$result = mysql_query("SELECT * FROM mail_list_db where '$LName' = last_name") or die(mysql_error());
The new records are being saved and I have tried it with many different e-mail addresses.