在html中创建表单非常简单 . 只需将要提交的数据放在表单元素中即可 . 在此示例中, period 放在带有隐藏属性的 input tag 中,我们从您的查询中分配值 .
<?php while($row = $db->fetch(PDO::FETCH_ASSOC)): ?>
<?php echo $row['student_name']; ?><?php echo $row['Passport_no'] ?><?php echo $row['Teacher'] ?><?php echo $row['Class'] ?><?php echo $row['Period'] ?>PresentAbsent
为了将表单保存到数据库,我们需要一个数据库连接,这里我使用了PDO mysql .
saveattendance.php
require_once 'dbconnect.php';//contains PDO connection script
if(isset($_POST['attendanceData'])){
$today = date('Y-m-d');
$period = $_POST['period'];
foreach($_POST['attendance'] as $key =>$val){
$studentid = $key;
$status = $val;
if(!empty($studentid)){
try{
$dbh->beginTransaction();
$stmt = $dbh->prepare("INSERT INTO `attendance` (`stud_id`,`Period`, `Status`,`Date`)VALUES(?,?,?,?)");
$stmt->execute(array($studentid, $period, $status, $today));
$update = $stmt->rowCount();
$dbh->commit();
}catch(PDOException $e){
$dbh->rollBack();
$error = $e->getMessage();//Print the error
exit;
}
}else{
//Student ID not there
}
}
}else{
//Form not submitted, display other useful info
}
?>