Senior Gamer Senior Gamer - 2 months ago 29
PHP Question

Email already exists

Alright so for some reason, Im always getting that email already exists if it doesnt.

public function emailExists($mail) {
$handler = new sql();
$sql = $handler->connect();

$sql->real_escape_string($mail);

$result = $sql->query("SELECT email FROM users WHERE email='".$mail."'");



if($result->num_rows != 0) return true;
else {
$handler->log_write($mail, "register_fail","NULL");
return false;
}
$sql->close();
return false;
}


Now here is the check

if($user->emailExists() == false) {
$user->create($name, $pass, $email, $age, $gender);
jquery_alert("You have been registered. Thank you for using our services. Enjoy your stay!");
jquery_reload();
}
else {
jquery_alert("This email already exists");
}

Answer

Pass email address as argument in method.

if($user->emailExists($email) == false) {
// your code here
}