IF语句不检查PHP中的所有条件

时间:2013-06-12 14:50:01

标签: php

if ($fname <> "" and $lname <> "" and $theemail <> "" and $empid <> "" and $doh <> "" and $ydept <> "#") {
    if ($percentage >= 85) {
        mail ($myEmail, $mailSubject, $msgBody, $header);
        mail ($userEmail, $sentMailSubject, $sentMailBody, $sentHeader);
        $filename = "output_annualexam.txt"; #Must CHMOD to 666, set folder to 777
        $text = "\n" . str_pad($fname, 25) . "" . str_pad($lname, 25) . "" . str_pad($empID, 15) . "" . str_pad($doh, 15) . "" . str_pad($tdate, 20) . "" . str_pad($ydept, 44) . "" . str_pad($percentage, 0) . "%";

        $fp = fopen ($filename, "a"); # a = append to the file. w = write to the file (create new if doesn't exist)
        if ($fp) {
            fwrite ($fp, $text);
            fclose ($fp);
            #echo ("File written");
        }
        else {
            #echo ("File was not written");
        }
        header ("Location: congrats.php?fname=$fname&type=$type");
    }
    else {
        header ("Location: nopass.php?percent=$percentage&type=$type");
    }
}
else {
    header ("Location: tryagain.php?type=$type");
}

当$ ydept ==“#”时,表示用户没有从SELECT选项中选择任何会使IF语句失败的部门,这会自动将用户带到tryagain.php页面,而是将它们带到nopass.php页面。所以某处失败了。

我应该尝试&amp;&amp; 而不是 AND 吗?但我认为它不应该有所作为。

1 个答案:

答案 0 :(得分:4)

是的,您应该使用&&而不是AND

由于我没有足够的口才来解释它,所以这里有一篇很好的帖子,感谢评论员;)

'AND' vs '&&' as operator