I am a newbie in PHP and i am trying to create a system where user will add firstname, lastname and email address. Basically what i am trying to do is verify if the e-mail already exists in database or not.
Have been working for hours but it doesn't work. But when i try to verify the firstname and lastname they both works.
But with email field ... the code cannot compare that there are duplicate values. There are lot of duplicate email Id in the database but the code ignores that and inserts the value :/. Meanwhile if i try verifying for duplicate firstname and lastname it works
Any help please :(
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$firstname= stripslashes($firstname);
$lastname= stripslashes($lastname);
$email= stripslashes($email);
$host="localhost";
$user="root";
$pass="";
$db="site";
$link=mysql_connect($host,$user,$pass);
mysql_select_db($db,$link);
$test="SELECT * FROM email_list WHERE email = '$email' ";
$select=mysql_query($test);
if(mysql_num_rows($select)>0)
{
echo "Email already exists".$email."<br>";
echo "Please enter another email";
}
else
{
$query="INSERT into email_list (first_name, last_name, email) values ('$firstname', '$lastname', '$email')";
mysql_query($query);
echo "values entered" .$firstname. "<br>". $lastname. "<br>". $email;
}