我使用 PHP 做了一个简单的测验评分,但它出现了无法识别的偏移错误,但它工作正常。
错误:
Notice: Undefined offset: 0 in C:\Users\scorequiz1.php on line 17
Notice: Undefined offset: 1 in C:\Users\scorequiz1.php on line 18
Notice: Undefined offset: 2 in C:\Users\scorequiz1.php on line 19
Notice: Undefined offset: 3 in C:\Users\scorequiz1.php on line 20
Notice: Undefined offset: 4 in C:\Users\scorequiz1.php on line 21
Notice: Undefined offset: 0 in C:\Users\scorequiz1.php on line 52
Question 1. Correct.
Notice: Undefined offset: 1 in C:\Users\scorequiz1.php on line 52
Question 2. Incorrect.
Notice: Undefined offset: 2 in C:\Users\scorequiz1.php on line 52
Question 3. Correct.
Notice: Undefined offset: 3 in C:\Users\scorequiz1.php on line 52
Question 4. Correct.
Notice: Undefined offset: 4 in C:\Users\scorequiz1.php on line 52
Question 5. Incorrect.
第 17 至 21 行:
$data[0] = $_POST["a"];
$data[1] = $_POST["b"];
$data[2] = $_POST["c"];
$data[3] = $_POST["d"];
$data[4] = $_POST["e"];
第 50-56 行:
for($i = 0; $i < 5; $i++)
{
if($answer[$i] == 1)
echo "Question " . ($i+1) . ". " . "Correct.<br/>";
else
echo "Question " . ($i+1) . ". " . "Incorrect.<br/>";
}
我的测验就是这样。问题的选项具有名称“a”到“e”以及检查正确答案的值
<!-- question 1---->
<INPUT TYPE="radio" NAME="a" VALUE="1">10 days<BR>
<INPUT TYPE="radio" NAME="a" VALUE="1">40 days<BR>
<!-- question 2---->
<INPUT TYPE="radio" NAME="b" VALUE="1">True<BR>
<INPUT TYPE="radio" NAME="b" VALUE="1">False<BR>
我不确定有什么问题