我在每个表格行中都有一个复选框,并且我想按下“保存”,它将循环显示每个复选框: (如果选中) - >输入到此学生已参与的数据库 否则 - >进入该学生尚未参加的数据库。循环播放PHP中的复选框
我的PHP代码:
<table border="1" cellpadding="1" width="550px" style="text-align:center;">
<th> Student ID </th>
<th> First Name </th>
<th> Last Name </th>
<th> Class ID </th>
<th> Attended </th>
<?php
$classid = $_GET['classid'];
$mysql_host='localhost';
$mysql_user='root';
$mysql_password='';
$con = @mysqli_connect($mysql_host,$mysql_user,$mysql_password);
if(!$con){
die('Failed to connect to the database');//if not successful
}else{
//echo "Successfully connected to MySQL!";//if successful
if(@mysqli_select_db($con, 'application_database')){//selecting the database
//echo '<br>'."Connected to the specified database!";
}else{
die('<br>'."Could not connect to the specified database!");
}
}
$sql="SELECT * FROM `student` WHERE class = '$classid'";
$records=mysqli_query($con,$sql);
while($student=mysqli_fetch_assoc($records)){
echo "<tr>";
echo "<td>".$student['id']."</td>";
echo "<td>".$student['first_name']."</td>";
echo "<td>".$student['last_name']."</td>";
echo "<td>".$student['class']."</td>";
echo "<td>".'<input type="checkbox" name="attendedCB">'."</td>";
}
echo '<form>';
echo 'Teacher ID: <input type="number" name=teacher_id>';
echo '<button name="save" type="submit">Save Attendance</button>';
echo '</form>';
?>
</table>
我有一个数据库中的“student_attendance”表,所以我想每一个学生与他/她的“出席”复选框的状态一起加入。干杯:D
使复选框成为一个数组''输入类型=“复选框”名=“出席的CB []”>然后你可以循环'$ _POST ['involveCB']' – RiggsFolly
规则:所有输入必须存在'
' – RiggsFolly使用'@'错误消音器只是让你在你的错误黑暗。在发展中你需要知道你在做什么错误 – RiggsFolly