I have a form with checkboxes of student names that is displayed on a class detail page. If you submit the form, it allows you to assign students to the class.
If you revisit the page, it remembers which students have been assigned to the class, and automatically checks their corresponding boxes. The form allows you to check additional students and submit the form, and they will added to the class.
What I'm having trouble with is actually removing students from the class. Specifically, how can I track which students have been "unchecked" on the class detail page, and pass them on to the form action page, where I can then loop an SQL DELETE statement over them?
Here is the code that I have been toying with:
$class_id = $_GET['class_id'];
$tid = $_POST['teachers'];
$student_count = $_GET['student_count'];
mysqli_query($db,"UPDATE class SET teacher_id = $tid WHERE id=$class_id");
if (isset($_POST['students'])) {
$students = $_POST['students'];
foreach ($students as $student_id) {
if (count($students) < $student_count) {
foreach (/*student that was unchecked from the class.php form*/) {
//delete statement
}
break;
} else {
mysqli_query($db, "UPDATE student_class SET student_id = $student_id WHERE class_id = $class_id");
mysqli_query($db,"INSERT INTO student_class (student_id, class_id) VALUES ($student_id, $class_id)");
}
}
}