Jump to content

Check if email already in MySql DB


monkeybidz

Recommended Posts

I am trying to check if email already in DB. This is what I have so far and does not work.

if($email){
// checking user input
$check_email=mysql_query("SELECT * FROM userlist WHERE email ='".$email."' ");
$get_email=mysql_fetch_array($check_email);
$existsmail=$get_email['email'];

  if($email == $existsmail){
$resultado = "Email address already exists!";
}	
  if($email != $existsmail){
    $resultado = "Your Account was created successfully! You may now login."; 
$date=getdate();
$insert=mysql_query("INSERT INTO userlist VALUES ('', '$name', '$phone', '$fax', '$company_name', '$billing_address', '$billing_city', '$billing_state', '$billing_zip_code', '$email', AES_ENCRYPT('$mysecretkey''password') ,now())");
  }else{
    $resultado = "";
	}
echo $resultado;
}

 

Thanks in advance.

Link to comment
Share on other sites

Define "doesn't work". Also, where does $email come from?

 

You don't have to fetch results with this query, you can just check if any were found with mysql_num_rows().

 

$check_email=mysql_query("SELECT * FROM userlist WHERE email ='".$email."' ");

if (mysql_num_rows($check_email) > 0) {
     // email found
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.