Jump to content

trying to check wether a emailaddress already exists in db at user registration


louis_coetzee

Recommended Posts

function EmailCheck()
{
extract($_POST);
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'mydatabase';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
$result = mysql_query("SELECT * FROM account where email = '$email'");

while ($row = mysql_fetch_array($result))
{
	$dbemail = $row['email'];
}
if ($dbemail == $email)
{
	echo 'The email address you have entered already exist. If you have forgotten your details please <a href="#">click here</a>.';
}else
	{
		return true;
	}
}

 

I have used this before, but now it won't work. Please help.

function EmailCheck($email) {
  
  $dbhost = 'localhost';
  $dbuser = 'root';
  $dbpass = '';
  $dbname = 'mydatabase';
  $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
  mysql_select_db($dbname);
  
  $email = mysql_real_escape_string($email);
  if ($result = mysql_query("SELECT * FROM account where email = '$email'")) {
    return mysql_num_rows($result));
  }

}

// usage example.

if (CheckEmail($_POST['email'])) {
  echo 'The email address you have entered already exist. If you have forgotten your details please <a href="#">click here</a>.';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.