4

我的问题:

我有一个密码检查器,可确保密码在插入数据库之前不超过 25 或 <5 个字符。如果是,它会吐出一个错误。这一切都很完美,但是我似乎无法检查密码是否不是 <5 或 >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 ...");
}
4

1 回答 1

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 ...");
}
于 2012-12-08T23:29:30.053 回答