尝试制作简单的评分系统时出现PHP错误500

时间:2019-06-25 03:52:28

标签: php

我正在尝试创建一个简单的评分系统,如果在文本框中输入某个值并提交该值,它将在下一页显示评分,而我得到的是一个错误500代码,我相信它有一些东西与我编写代码的方式有关。

我不确定这样写是否正确:

if($ a <= 60){ echo =“ F”}

elseif ...

    <body>
        <center>
            <div class="container">
                <form action="cek_grade.php" method="post"> <!--Action: Sent to "cek_grade.php" Method: The data will be displayed by "post"-->
                   Nilai: <input type="integer" name="nilai"> <!--The name of the numbers inputted are "nilai"-->
                   <br><br>
                   <input type="submit" id="submit" name="submit" value="Submit">
                   <input type="reset" id="reset" name="reset" value="Reset">
                </form> <!--All the data above should get sent to the page called "cek_grade.php"-->
            </div>
       </center>
    </body>

<?php

        nilai = $_POST ['nilai'];
        echo = "$nilai"

        if($nilai <= 60) {
        echo = "F"
        } elseif ($nilai <= 70) {
        echo="C"
        } elseif ($nilai <= 80) {
        echo="B"
        } else {
        echo="A"

>

我想做的是,如果变量“ $ nilai”在某个值范围内,它将显示F,C,B或A的等级。

3 个答案:

答案 0 :(得分:0)

你错过了很多事情

<body>
        <center>
            <div class="container">
                <form action="cek_grade.php" method="post"> <!--Action: Sent to "cek_grade.php" Method: The data will be displayed by "post"-->
                   Nilai: <input type="integer" name="nilai"> <!--The name of the numbers inputted are "nilai"-->
                   <br><br>
                   <input type="submit" id="submit" name="submit" value="Submit">
                   <input type="reset" id="reset" name="reset" value="Reset">
                </form> <!--All the data above should get sent to the page called "cek_grade.php"-->
            </div>
       </center>
    </body>

<?php
    $nilai = $_POST['nilai'];
    echo $nilai;

    if($nilai <= 60) {
      echo "F";
    } elseif ($nilai <= 70) {
      echo "C";
    } elseif ($nilai <= 80) {
      echo "B";
    } else {
      echo "A";
    }
?>

答案 1 :(得分:0)

您的脚本有几处错误:

  • 您对$nilai的首次引用缺少$
  • 您无法分配给echo
  • 在大多数行的末尾都缺少分号。
  • 您在$POST ['nilai]中的空格无效。

这是一个有效的版本:

$nilai = $_POST['nilai'];
echo "$nilai";

if($nilai <= 60) {
    echo "F";
} elseif ($nilai <= 70) {
    echo "C";
} elseif ($nilai <= 80) {
    echo "B";
} else {
    echo "A";
}

答案 2 :(得分:0)

我不会介绍HTML部分,但这是您更正的PHP脚本

<?php
    $nilai = $_POST ['nilai'];
    echo $nilai;

    if($nilai <= 60) {
    echo "F";
    } elseif ($nilai <= 70) {
    echo "C";
    } elseif ($nilai <= 80) {
    echo "B";
    } else {
    echo "A";
}
?>