Currently, I am working on the attendance form. In this interface, it consists rows of student(get from student table). The list of students are viewed in the table. the first column is NO, second column in Birth No, third STudent Name, forth Attendance. in column attendance, there are three radio button which is PT, AT, and MC which their value is present, absent, and mc respectively. The outside of the table, there is a submit button. Teacher needs to click which attendance of the student, either pt, at or mc. Teacher needs to click for all students. When submit button clicked by teacher, attendance of the students will be inserted into the database. When I execute code below, there nothing value is inserted in the database. Can some please help me to figure it out where i went wrong? I worked on this code for past 2 weeks yet still not getting an expected result. Thank you.
$getdata = mysql_query("select * from student where
class = '$class' order by name ") or die(mysql_query);
if (isset($_POST['submit'])){
$id = 1;
while($row = mysql_fetch_assoc($getdata)){
if(isset($_POST['a'.$id])) {
$status = $_POST['a'.$id];
if(!empty($status)){
if(($status == "present" || $status == "mc")){
$attend = 1;
}
else if($status == "absent"){
$attend = 0;
}
$query = "INSERT INTO attendance(birth_no, date, status, attend)
VALUES ('$birth_no','$date','$status','$attend')";
if($query_run = mysql_query($query)){
echo 'Insert attendance done';
}
else{
echo'Attendance not inserted.';
}
}
else{
echo 'Please enter all fields';
}
}
$id ++;
}
}
else {
?>
<form action="addattend.php" method = "POST">
<table>
<?php
$id = 1;
while($row = mysql_fetch_assoc($getdata)){
$birth_no= $row['birth_no'];
$name = $row['name'];
?>
<tr>
<td><center><?php echo $id ?></center></td>
<td><center><?php echo $date ?></center></td>
<td><center><?php echo $birth_no ?></center></td>
<td><center><?php echo $name ?></center></td>
<td>
<input type="radio" name="a<?php echo $id; ?>" value="present">PT
<input type="radio" name="a<?php echo $id; ?>" value="absent">AT
<input type="radio" name="a<?php echo $id; ?>" value="mc">MC
</td>
</tr>
<?php
$id ++;
} // end while
?>
</table>
<center><input type="submit" name="submit" value="Submit"></center>
</form> <!-- end the form here -->
<?php
} // end else
?>
this is what i meant about the interface(picture below)
for every row, there are 3 radio buttons. The list of student was retrieved from the database. Teachers need to select the attendance for all students. with a single submit button, All the attendance will be inserted in the database with birth_no, date(selected earlier by teacher) and also $attend which is assigned after attendance selected.