我犯了一个PHP的形式,并创造了这个错误处理脚本:显示文本GET
<?php
if(isset($_GET["alert"])) {
$alert = $_GET["alert"];
if($_GET["alert"]="nofilled") {
echo "<div class='error'>You missed something!</div>";
}
elseif($_GET["alert"]="badpass") {
echo "<div class='error'>Your passwords don't match!</div>";
}
elseif($_GET["alert"]="badusername") {
echo "<div class='error'>Your username is too long!</div>";
}
elseif($_GET["alert"]="shortpass") {
echo "<div class='error'>Your password is too short!</div>";
}
elseif($_GET["alert"]="takenusername") {
echo "<div class='error'>That username is taken!</div>";
}
elseif($_GET["alert"]="takenemail") {
echo "<div class='error'>That email already has an account attached to it!</div>";
}
}
?>
我试图与“badpass”的GET值运行。出于某种原因,它回应了'没有填充'的信息。
我正在学习这一点,我找不到解决方案。你可以快速查看,看看有什么不对?
这是=':
甚至更好(更DRY),只需使用一个数组而不是所有'if'中的'=='GET –
在您的条件下使用== –
或者,您应该始终使用“===”,除非您有理由不这样做。 – ragol