How to check if an email address exists. Check

I cannot figure out how to check if a letter exists in my database. Currently, users use their email address to enter my site with a password, but now the user can register more than once with the same email address, which causes big problems on my site. Some research has been done, but it seems they cannot solve it.

Can someone help me?

<?php if(isset($_POST['add'])) { $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'pass'; $db = "db"; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not send your enquiry at this time please try again later.'); } $phone = mysql_real_escape_string((string)$_POST['phone']); $email = mysql_real_escape_string((string)$_POST['email']); $password = mysql_real_escape_string((string)$_POST['password']); $firstname = mysql_real_escape_string((string)$_POST['firstname']); $surname = mysql_real_escape_string((string)$_POST['surname']); $country = mysql_real_escape_string((string)$_POST['country']); $nationality = mysql_real_escape_string((string)$_POST['nationality']); $yearofbirth = mysql_real_escape_string((string)$_POST['yearofbirth']); $profession = mysql_real_escape_string((string)$_POST['profession']); $status = mysql_real_escape_string((string)$_POST['status']); $membertype = 'Registered'; $dateregistered = mysql_real_escape_string((string)$_POST['dateregistered']); $agreedtoterms = mysql_real_escape_string((string)$_POST['agreedtoterms']); $sql = "INSERT INTO members (phone, email, password, firstname, surname, country, nationality, yearofbirth, profession, uniquepin, status, membertype, dateregistered, agreedtoterms) VALUES('$phone', '$email', '$password', '$firstname','$surname','$country','$nationality','$yearofbirth','$profession','$uniquepin','$status','$membertype','$dateregistered', '$agreedtoterms')"; mysql_select_db($db); $retval = mysql_query( $sql, $conn )or die(mysql_error()); ?> 
+4
source share
3 answers

You can make the email column a unique constraint - then the request will fail when trying to insert.

You can also just request it ....

 SELECT `email` FROM `members` WHERE `email` = '$email' LIMIT 1 

If you get the result, the letter exists.

+5
source

Before adding a unique restriction to the login table, he needs to consolidate duplicate email records (otherwise this restriction will not succeed) into one record and notify users about this.

If emails are unique at the data level, he can then add a restriction. Finally, before creating a new login entry, he runs a query to see if the mailing address exists.

There must be an SO stream for this: based on email 101; -)

+1
source
 $query_ch_email = mysql_query("SELECT email FROM members WHERE email = '$email' LIMIT 1") or die(mysql_error()); if (mysql_num_rows($query_ch_email) > 0) { $notices['register'][] = 'Your e-mail already exist'; } if (!count($notices['register'])) { $sql_insert = "INSERT INTO members ( phone , email , password , firstname , surname , country , nationality , yearofbirth , profession , uniquepin , status , membertype , dateregistered , agreedtoterms ) VALUES ( '$phone' , '$email' , '$password' , '$firstname' , '$surname' , '$country' , '$nationality' , '$yearofbirth' , '$profession' , '$uniquepin' , '$status' , '$membertype' , '$dateregistered' , '$agreedtoterms' )"; mysql_query($sql_insert)or die(mysql_error()); } 
-1
source

All Articles