我正在尝试为注册页面设置字符限制,无论用户名是什么太长都可以告诉我什么是错的? see the error for your self
if(mb_strlen($uname) >= 20){
if(mb_strlen($uname) <= 6){
if(mb_strlen($pass1) <= 8){
if(mb_strlen($pass1) >= 16){
if((mb_strlen($email)) > 5 && strstr(($email1), "@") && strstr(($email1),".")){
$pass = md5(md5("47Jdfio209".$pass1."4jfhioJasify3"));
$pass = hash('sha512',$pass);
$sql = $mysqli -> query("SELECT * FROM `archewor_users`.`users` WHERE `uname` = '$uname'");
if(mysqli_num_rows($sql) > 0){
echo"Sorry, that user already exists.";
exit();
}
$mysqli -> query("INSERT INTO `archewor_users`.`users` (`id`, `name`, `lname`, `uname`, `email`, `pass`) VALUES (NULL, '$name', '$lname', '$uname', '$email1', '$pass')") or die(mysqli_error());
}else{echo 'Your email must be valid.';}
}else{echo 'This password is too long';}
}else{echo 'This password is too short';}
}else{echo 'This username is too short';}
}else{echo 'This username is too long';}
}else{
echo "Sorry, your passwords do not match.<br />";
exit();
}
}else{
echo "Sorry, your emails do not match. <br /> <br />";
}
}else{
答案 0 :(得分:0)
您撰写的逻辑不正确。检查用户名和密码验证的条件。书面代码标准很差。使用条件运算符而不是嵌套if条件。
答案 1 :(得分:0)
这只是一个逻辑错误
// 1. Here you check, if your username is to LONG
// So your -else- is called, if your username is to SHORT
if(mb_strlen($uname) >= 20){
// all the rest
} else {echo 'This username is too long';} // This message should be "Username is to short"
也许更好:
if(mb_strlen($uname) >= 20)
die("Username is to long");
if(mb_strlen($uname) <= 6)
die("Username is to short");