我的问题:
我有一个密码检查程序,可以确保密码在插入数据库之前不是> 25或<5个字符。如果是,则会发出错误。这一切都很完美,但我似乎无法检查密码是否不是&lt; 5和/或&gt; 25个字符然后将它放入数据库。
代码部分:
if (strlen($pswd)>30) {
echo "Your password is too long! Password's should be between 5 and 30 characters long!";
}
if (strlen($pswd)<5) {
echo "Your password is too short! Password's should be between 5 and 30 characters long!";
}
else if (!strlen($pswd)>30||strlen($pswd)<5)
{
$query = mysql_query("INSERT INTO users VALUES ('','$un','$fn','$ln','$em','$pswd','$d','0')");
die("<h2>Welcome to M8Ster</h2>Please login to your account to get started ...");
}
答案 0 :(得分:4)
尝试将所有if语句组合成一个if-elseif-else:
if (strlen($pswd)>30) {
echo "Your password is too long! Password's should be between 5 and 30 characters long!";
} else if (strlen($pswd)<5) {
echo "Your password is too short! Password's should be between 5 and 30 characters long!";
} else {
$query = mysql_query("INSERT INTO users VALUES ('','$un','$fn','$ln','$em','$pswd','$d','0')");
die("<h2>Welcome to M8Ster</h2>Please login to your account to get started ...");
}