检查多个学生的一个复选框后,只有一个学生存储在我的数据库中。我想获得每个学生的复选框的值,添加管理员的每个输入。还有一件事是我要复制表格中第一个名称和部分的数据//请参阅对“出勤”数据库的评论。表中值的数据库是“student”。提前致谢。
<html> <body> <form method = "POST"><strong> Set the date: </strong> <input type = "date" name = "set_date"></br></br> <table width="800" border="3" cellpadding="1" cellspacing="1"> <tr> <th><center>First name</center></th> <th><center>Section</center></th> <th><center>Status</center></th> </tr>
<?php
$con = mysql_connect("localhost", "root", "avtt123");
mysql_select_db("arvintarrega",$con);
$query = mysql_query("SELECT * FROM student");
echo "<form action = attendance.php method = POST>";
while($student=mysql_fetch_array($query))
{
echo "<tr>";
echo "<td><center>".$student['fname']."</center></td>"; // the 'fname' and the 'section'
echo "<td><center>".$student['section']."</center></td>";
echo '<td><center><input type = "checkbox" name = "status" value = "Present">Present </input>';
echo '<input type = "checkbox" name = "status" value = "Absent">Absent </input>';
}
echo "</form>";
echo "</table>";
if(isset($_POST['save']))
{
if(filter_input(INPUT_POST, 'set_date') && filter_input(INPUT_POST, 'status'))
{
if(isset($_POST['set_date']) && ($_REQUEST['status']=="Present"))
{
$sql = "INSERT INTO attendance(date, status) VALUES('$_POST[set_date]', '$_REQUEST[status]')";
echo '<span style="color:green;"><strong></br>Attendance Complete!<strong></span>';
}
else if(isset($_POST['set_date']) && ($_REQUEST['status']=="Absent"))
{
$sql = "INSERT INTO attendance(date, status) VALUES('$_POST[set_date]', '$_REQUEST[status]')";
echo '<span style="color:green;"><strong></br>Attendance Complete!<strong></span>';
}
mysql_query($sql, $con);
}
else
echo '<span style="color:red;"><strong></br>All fields are required</strong></span>';
}
?>
</br></br>
<input type = "submit" name = "save" value = "Submit>
</form>
</body>
</html>