PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1845
Number of posts: 5013

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Problem with function Posted by oashaikh on 27 Dec 2010 at 3:40 PM
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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.