驗證我有一個頁面上此PHP腳本這需要從變量輸入字段:IF語句不能在PHP
if($fname <> "" and $lname <> "" and $ydept <> "") {
if ($percentage >= "85") {
mail ($myEmail, $mailSubject, $msgBody, $header);
mail ($userEmail, $sentMailSubject, $sentMailBody, $sentHeader);
$filename = "blah.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) . "";
$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: yes.php?fname=$fname&type=$type");
}
else {
header ("Location: didnotpass.php?percent=$percentage&type=$type");
}
}
else {
header ("Location: empty.php?type=$type");
}
而且didnotpass.php腳本是:
<?php
if (isset($_GET['type']) && isset($_GET['percentage'])) {
$percent = trim(strip_tags(stripslashes($_GET['percent'])));
$type = trim(strip_tags(stripslashes($_GET['type'])));
if ($type == "Clinical") {
?>
The Certificate of Attendance has been completed yet, but your score of $percent% is less then the passing score of 85%.<br><br>
Please <b><a href="C.php">Click Here</a></b> to retake the certification.
<?php
}
else {
?>
The Certificate of Attendance has been completed yet, but your score of $percent% is less then the passing score of 85%.<br><br>
Please <b><a href="nonC.php">Click Here</a></b> to retake the certification.
<?php
}
}
else {
?>
Please <b><a href="start.php">Go To Certification Homepage</a></b> to start the certification.
<?php
}
?>
我的問題具有是否得分是85%或不是,它進入最後一條語句:
Please <b><a href="start.php">Go To Certification Homepage</a></b> to start the certification.
是我的IF語句correc T:
if ($percentage >= "85")
我想這是正常工作,因爲它被路由到正確的頁面,但在didnotpass.php的if/else語句無法正常工作。任何人都可以幫我修復它?
這似乎很容易檢查:在'if'條件給你之前'var_dump($ percent);'是什麼,你爲什麼要引用nu MBER? – jeroen 2013-03-11 21:24:06
我的nopass.php網址如下所示:http://www.imed.com/sc/nopass.php?percent=38&type=Clinical – Si8 2013-03-11 21:28:43
你知道,這並不是說這可以解決你的問題,但它可能是一個壞主意在數字周圍使用引號。只要做'85'不加引號。 – Mike 2014-04-03 00:52:53