出勤系统标记学生出现/缺席复选框,更新Mysql PHP

时间:2013-03-12 16:33:42

标签: php html mysql

场景:我正在为一所大学制作一个考勤系统,但是我一直坚持更新mysql并使用复选框来标记学生缺席或在场。

所以目前我已设法过滤我想要显示的数据。这是student_id,fname,lname,present。请参阅以下代码

<strong>Class Register:</strong> </br>

<?php

$test3= "SELECT * FROM course_attendance, students, courses, attendance WHERE course_attendance.course_id=courses.course_id AND course_attendance.week_id=attendance.week_number_id AND course_attendance.student_id= students.student_id AND courses.course_id='101' AND attendance.week_number_id='2' ";
$result = mysql_query($test3)  or die(mysql_error());


echo "</br><table border='1' align='center'><tr> <th><strong>Student ID</strong></th> <th><strong>First Name </strong></th> <th><strong>Last Name</strong></th> <th><strong>Present</strong></th> </tr> ";

while($rows=mysql_fetch_array($result)){

    echo "<tr><td width='100' align='center'>" .$rows['student_id'].
"</td><td width='120' align='center'>" .$rows['fname'].
"</td><td width='120' align='center'>" .$rows['lname'].
"</td><td width='120' align='center'>" .$rows['present'].  
"</td><tr width='120' align='center'>";
}
echo "</table>";
?>

目前,这显示了数据:student_id,fname,lname,present。

我的MySQL中的'Present'字段是一个无符号的tinyint,我希望能够将它设置为一个复选框,这将使用户能够标记存在或不存在的学生,然后更新到mysql。此外,我不希望编辑学生ID,fname和lname,只是当前字段。这可能吗?

如果有人成功帮助我,请提前感谢,我将永远感激不尽!

1 个答案:

答案 0 :(得分:2)

您可以在表单中选中一个复选框:

<input type='checkbox' class='form' value='Yes' name='checkbox_attendance'/> Present?

然后检查该字段的值并将其存储在数据库中:

if(isset($_POST['checkbox_attendance']) && $_POST['checkbox_attendance'] == 'Yes') {
    //Store the value of checkbox_attendance (Yes) into the database
} else {
    //Store 'No' into the database
}
除非你这样做,否则

student_id,fname和lname将不可编辑。 在互联网上有很多关于PHP表格的信息,看看那些。

相关问题