monkeybidz Posted January 3, 2012 Share Posted January 3, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/254247-check-if-email-already-in-mysql-db/ Share on other sites More sharing options...
scootstah Posted January 3, 2012 Share Posted January 3, 2012 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 } Quote Link to comment https://forums.phpfreaks.com/topic/254247-check-if-email-already-in-mysql-db/#findComment-1303571 Share on other sites More sharing options...
monkeybidz Posted January 3, 2012 Author Share Posted January 3, 2012 Thanks Scootstah! The email comes from a form POST and echo's fine. I will give your code a try. Quote Link to comment https://forums.phpfreaks.com/topic/254247-check-if-email-already-in-mysql-db/#findComment-1303577 Share on other sites More sharing options...
monkeybidz Posted January 3, 2012 Author Share Posted January 3, 2012 Awsome! Thanks scootstah. That worked. Quote Link to comment https://forums.phpfreaks.com/topic/254247-check-if-email-already-in-mysql-db/#findComment-1303580 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.