我正在制作一份学生名单,以便用户可以标记他们的缺席。我想要一个表格,其中包含用户名册上每个学生的复选框及其姓名。我有代码来生成它。一旦我点击提交,我如何编写一个查询,使用所有选中的框将日期与每个学生的 id 添加到数据库中?
这是我的代码:
$nameDB = "teacheasy";
$connection = new mysqli($servername, $usernameDB, $passwordDB, $nameDB);
$sqlListStudents = "SELECT CONCAT(last_name,', ',first_name) AS 'StudentName' FROM `students` WHERE teacher_id='" . $_SESSION['userId'] . "' ORDER BY last_name ASC;";
$resultListStudents = mysqli_query($connection, $sqlListStudents) or die("Bad Query: $sqlListStudents");
echo "<form method='post'>";
echo"<table>";
echo"<tr>
<td><b>Mark Today's Absesences Only</b></td>
</tr>";
$nameCount = 0;
while($row = mysqli_fetch_assoc($resultListStudents)){
echo"<tr><td><input type='checkbox' name='student". $nameCount ."'>{$row['StudentName']}</td></tr>";
$nameCount++;
}
echo "</table>";
echo "<button type='submit' name='submitAbsences' class='navButton'>Submit Absences</button>";
echo "</form>";
if(isset($_POST['submitAbsences'])){
}
这是我的输出。 点击这里,由于是新帐户,我还不能放图片。