I have generated checkboxes dynamically and want to insert into att field in attendance table.. ie when user checks the checkbox P would be inserted and when he does not check A would be inserted.. I am trying out attendance system for students.. here is what i have tried..
<?php
$report = mysql_query("SELECT id, studname, studroll FROM student") or die(mysql_error());
?>
<form action="attendance.php" method="post">
<table id = "attendance" width="567" border="1">
<tr>
<th width="83" scope="col">ID</th>
<th width="83" scope="col">Student Name</th>
<th width="55" scope="col">Student Roll.No</th>
<th width="51" scope="col">Attendance</th>
<th width="276" scope="col">Remarks of Absentees</th>
</tr>
<?php while(list($id, $studname, $studroll) = mysql_fetch_row($report))
{
?>
<tr>
<td><?php echo $id ?></td>
<td><?php echo $studname ?></td>
<td><?php echo $studroll ?></td>
<td align="center"><?php echo '<input type="hidden" name="att[]" value="0"/>';?><?php echo '<input type="checkbox" checked="checked" name="att[]" value="1" />'; ?></td>
<td align="center"><label for="remarks"></label>
<input type="text" name="remarks" id="remarks" /></td>
</tr>
<?php
}
echo '</table>';
?>
<input type="submit" name ="submit2" id="submit2" value ="submit"></input>
</form>
and my attendance.php file
<?php
$att = $_POST['att'];
foreach($att as $key => $attendance) {
$at = $attendance ? 'P' : 'N';
}
$report = mysql_query("SELECT id FROM student") or die(mysql_error());
while(list($id) = mysql_fetch_row($report))
{
$query = "INSERT INTO `attendance`(`stud_id`,`att`) VALUES ('".$id."','".$at."') ";
$result = mysql_query($query);}
?>
I know i am doing some mistake in the loop but not able to figure out.. Any help??