我得到一个未定义的索引错误,这些变量:id,subj,mid,fin。我已经对它们进行了适当的定义,并且我不知道我的代码有什么问题。我认为问题出在我定义这4个变量的地方。请帮忙?谢谢。
echo "
ID:
Subject:
Midterm:
Finals:
";
$mysqli = mysqli_connect("localhost", "root", "", "school");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
$sql = "select * from studentgrades";
}
$id = $_POST['id'];
$subject = $_POST['subj'];
$midterm = $_POST['mid'];
$finals = $_POST['fin'];
$average = ($midterm + $finals) / 2;
if ($average >= 70) {
$remarks = 'Passed';
} else {
$remarks = 'Failed';
}
$res = mysqli_query($mysqli, $sql);
if ($res) {
$sql1 = "
update studentgrades set Subject = " . $subject . ",
Midterm = " . $midterm . ",
Finals = " . $finals . ",
Average = " . $average . ",
Remarks = " . $remarks . "
where ID = " . $id . "
";
$res1 = mysqli_query($mysqli, $sql1);
if ($res1) {
echo "
Grades updated successfully.
";
}
}