我正在尝试编写一些代码,这些代码从一组输入标签中获取输入,这些输入标签的生成是为了让每个学生的名字都紧挨着他们。 They look like this on the page.
点击提交(位于模式底部)后,屏幕仅显示标题,据我所知,不会修改数据库。
这是我的代码,试图获取输入数据并将其发送到数据库:
$sqlListStudents = "SELECT CONCAT(last_name,', ',first_name) AS 'StudentName',student_id FROM `students` WHERE teacher_id='" . $_SESSION['userId'] . "' ORDER BY last_name ASC;";
$resultListStudents = mysqli_query($connection, $sqlListStudents) or die("Bad Query: $sqlListStudents");
$doc = new DomDocument;
if (isset($_POST['submitNewAssignment'])){
$name = $_POST['students'];
$newAssignmentName = $_POST["newAssignmentName"];
if(empty($newAssignmentName)){
echo "<script>alert('New Assignment Name not set')</script>";
} else{
$sqlNewAssignmentName = "INSERT INTO assignments(subject_id,assignment_name,teacher_id) VALUES ('2',".$newAssignmentName.",".$_SESSION['userId'].")";
$forCount = 0;
mysqli_query($connection, $sqlNewAssignmentName) or die("Bad Query: $sqlNewAssignmentName");
foreach ($name as $students) {
$grade = $doc->getElementById("studentNum".$forCount);
$studentList= mysqli_fetch_assoc($resultListStudents);
$sqlSelectGradebook = "INSERT INTO grades(student_id,grade,gradebook_id)
VALUES(".$students.",".$grade.",
(SELECT gradebook_id FROM gradebooks
WHERE teacher_id=".$_SESSION['userId']." AND gradebook_title='Language Arts'))";
mysqli_query($connection, $sqlSelectGradebook) or die("Bad Query: $sqlSelectGradebook");
echo "for loop stuck";
}
echo "<script>alert('The grades were added.')</script>";
}
}