i'm playing around and trying to incorporate a nested function into my login script. The functions are all below. Also, beneath my functions is the portion of the login script im trying to incorporate them in. However, everytime I try to log in, it says invalid username. However if I user function a and b in the login script instead of function d, everything works fine. Can some tell me where i',m going wrong? Thanks.
//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';`
很好,函数d不返回任何值。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.