Hi, I have this function,
The problem is that the function for some reason will not check if an email already exists in the database
Can someone please check where I am going wrong
Here is the function so far:
function check_registration($email,$email2,$username,$pass1){
$pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
if (!ereg($pattern, $email)){
$msg = "<br />Please enter a valid email address";
}
$chk_email = mysql_query("SELECT email FROM users WHERE email='$email'") or die (mysql_error()."<br /> Could not get user email");
$chk_email2 = mysql_fetch_array($chk_email);
if ($chk_email2==$email){
$msg = "<br />That email already exists";
}
elseif ($email2 !== $email){
$msg = "<br />Your emails do not match";
}
//Check Username
if ($username == NULL){
$msg = "Please enter a username";
}
//Check Pass
if ($pass1 == NULL || strlen($pass1) < 8){
$msg = "<br />Please enter a password that is 8 or more characters";
}
else {$msg = "Registered Successfully";
}
echo $msg;
if ($msg == "Registered Successfully"){
$pass1 = md5($pass1);
$randid = rand(10000,999999999);
$insert_date = mysql_query("INSERT INTO users(UID,username,email,password) VALUES ('$randid','$username','$email','$pass1')") or die (mysql_error()."<br />Could not insert data");
$message = "http://localhost/new_game/login.php?action=validate&id=$randid";
require 'gmailer/class.phpgmailer.php';
$mail = new PHPGMailer();
$mail->From = 'oashaikh@gmail.com';
$mail->FromName = 'Admin';
$mail->Subject = 'Activate Account';
$mail->AddAddress($email);
$mail->Body = $message;
$mail->Send();
}
Thanks in advance