我正在尝试创建一个简单的评分系统,如果在文本框中输入某个值并提交该值,它将在下一页显示评分,而我得到的是一个错误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的等级。
答案 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";
}
?>