Scenario: I am making an attendance system for a college, however I have been stuck on updating mysql and using checkboxes to mark a student absent or present.
So currently I have managed to filter the data I want to be shown. this is student_id, fname, lname, present. Please see the code below
<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>";
?>
So currently, this shows the data: student_id, fname, lname, present.
The field 'Present' in my MySQL is a unsigned tinyint, I want to be able to make this a checkbox, which would enable the user to either mark a student present or absent and then update to mysql. Also I dont want the students id, fname and lname enabled to be edited, just the present field. Is this possible?
Thanks in advance if someone succesfully helps me , I will be forever grateful!
You can have a checkbox in a form for this:
<input type='checkbox' class='form' value='Yes' name='checkbox_attendance'/> Present?
Then you check for the value of that field and store it in the database:
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, and lname won't be editable unless you make it. There's a lot of information on PHP forms on the internet, take a look at those.