PHP的新功能...需要帮助...关于嵌套函数

时间:2012-02-20 05:12:18

标签: php function nested

我正在玩并尝试将嵌套函数合并到我的登录脚本中。功能都在下面。此外,在我的函数下面是我试图将它们合并到的登录脚本的一部分。但是,每次我尝试登录时,它都表示无效的用户名。但是,如果我在登录脚本而不是函数d中使用a和b函数,一切正常。有人可以告诉我我在哪里,我错了吗?感谢。

//a -username

function username_check($username){

$usercheck = "SELECT user_id FROM users WHERE username ='$username'";
$userqry = mysql_query($usercheck) or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($userqry);
return ($num_rows == 1) ? true : false;
}

//b - password

function password_check($password, $username){

$passwordcheck = "SELECT password FROM users WHERE username ='$username'"; 
$passwordqry = mysql_query($passwordcheck) or die ("Could not match data because ".mysql_error());

while($retrievepassword = mysql_fetch_array($passwordqry))  

{

 $password = md5($password);

 return ($password != $retrievepassword['password']) ? true : false;

 }
 }
 //c    -email

 function email_check($email){

 $emailcheck = "SELECT user_id FROM users WHERE email = '$email'"; 
 $emailqry = mysql_query($emailcheck) or die ("Could not match data because ".mysql_error());
 $num_rows = mysql_num_rows($emailqry); 

 return ($num_rows == 1) ? true : false;
 }

 //d -username + password + email check? all in one? DOESNT WORK

 function user_check($username = NULL, $password = NULL, $email = NULL) {

 if(($email !=NULL)) {
 email_check($email);
 }

 elseif(($username !=NULL) && ($password!=NULL)){
 password_check($password,$username);   
 }

 elseif(($username !=NULL) ) {
 username_check($username);
 }

 }


 //LOGIN SCRIPT

 if (user_check($username1) ==false) { 
    $logerrors[] = 'Invalid username';

 }
 elseif (user_check($password1, $username1)) { 
    $logerrors[] = 'Incorrect password';`

1 个答案:

答案 0 :(得分:4)

对于一个,函数d不会返回任何值。