0

入力フィールドから変数を取得するこのphpスクリプトが1ページにあります。

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%であるかどうかであり、最後のelseステートメントに進みます。

Please <b><a href="start.php">Go To Certification Homepage</a></b> to start the certification.

私のIFステートメントは正しいですか:

if ($percentage >= "85")

正しいページにルーティングされているため、正しく機能していると思いますが、didnotpass.phpのIF/ELSEステートメントが正しく機能していません。誰かが私がそれを修正するのを手伝ってくれる?

4

2 に答える 2

3
if ($percentage >= "85")

する必要があります:

if ($percentage >= 85)

数値を引用符で囲んで、それが>=と評価されることを期待することはできません。文字列として扱います。タイプによっては、整数として解析する必要がある場合もあります。

于 2013-03-11T21:24:53.123 に答える
2

何が起こっているのかは、クエリ文字列パラメーターpercentが一貫していないことだと思います:

if (isset($_GET['type']) && isset($_GET['percentage'])) {
    $percent = trim(strip_tags(stripslashes($_GET['percent'])));
    $type = trim(strip_tags(stripslashes($_GET['type'])));

そのはず

if (isset($_GET['type']) && isset($_GET['percent'])) {
    $percent = trim(strip_tags(stripslashes($_GET['percent'])));
    $type = trim(strip_tags(stripslashes($_GET['type'])));

if ステートメントは$_GET['percentage']代わりに参照します$_GET['percent']

于 2013-03-11T21:27:44.663 に答える