Problem with function - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Problem with function

oashaikhoashaikh Posts: 3Member
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:
[color=Red][code]
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 = "
Please enter a valid email address";
}
$chk_email = mysql_query("SELECT email FROM users WHERE email='$email'") or die (mysql_error()."
Could not get user email");
$chk_email2 = mysql_fetch_array($chk_email);

if ($chk_email2==$email){
$msg = "
That email already exists";
}
elseif ($email2 !== $email){
$msg = "
Your emails do not match";
}


//Check Username
if ($username == NULL){
$msg = "Please enter a username";
}



//Check Pass
if ($pass1 == NULL || strlen($pass1) < 8){
$msg = "
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()."
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();
}

[/code]
[/color]

Thanks in advance
Sign In or Register to comment.