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!


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:
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 = '[email protected]';
$mail->FromName = 'Admin';
$mail->Subject = 'Activate Account';
$mail->Body = $message;


Thanks in advance
Sign In or Register to comment.