<?PHP
session_start();
$_SESSION["teacher"] = "tech01";
echo "Favorite teacher is " . $_SESSION["teacher"] . ".<br>";
include 'db.php';
?>
<html>
<head></head>
<body>
<?php
if(isset($_POST['submit']))
{
$inst=$_POST['inst'];
$sub=$_POST['sub'];
$view_student="select s_name from students where s_inst='$inst' AND
s_sub='$sub' ";
$run=mysqli_query($dbcon,$view_student);
echo "<form name='form' action='atte.php' method='post'>";
echo '<input type="date" name="att">'; // currently for future use
echo "</br>";
while($row=mysqli_fetch_array($run)){
$name=$row['s_name'];
echo '<input type="checkbox" name="present" >';
echo "<label>" .$name. "</label>";
echo "<input type='hidden' name='stun' value='".$name."'/>";
echo "<input type='hidden' name='inst' value='".$inst."'/>";
echo "<input type='hidden' name='sub' value='".$sub."'/>";
echo '<input type="submit" value="Submit_attendance"
name="insert">';
echo "<br>";
}
echo "</form>";}
?>
每当我标记在场的学生时,它都标记所有在场的学生,我该如何保存? 这是在线考勤管理系统的代码。
答案 0 :(得分:0)
您需要改变三件事:
对于上面的第2步,您应该修改现有代码:
echo '<input type="checkbox" name="present" >';
到此:
echo "<input type='checkbox' name='present[{student_id}]' >";
请注意,echo语句使用双引号而不是单引号来允许解释变量student_id。
对于上面的第3步:
foreach($_POST['present'] as $student_id => $present) {
if ($present) {
echo "The student with id of $student_id is present";
}
}