Error message appears more that 1
I am working on this code to insert an attendance. This code is just fine.
But there are some output that I don't want it to reappears twice.I do not
know where exactly I need to correct it. Hope someone can rearrange my
code so that the out wont be like picture below.
$class = getfield('class');
$getdata = mysql_query("select * from student where class = '$class' order
by name ") or die(mysql_query);
$result = "select birth_no from student where class = '$class'";
$getbirth = mysql_query($result) or die(mysql_error());
if(isset($_POST['date']))
{
$_SESSION['date'] = $_POST['date'];
$date = $_POST['date'];
if(!empty($date))
{
while($row = mysql_fetch_assoc($getdata))
{
$id = $row["birth_no"];
$query = "SELECT * FROM attendance WHERE date = '$date' and
birth_no = '$id'";
$query_run = mysql_query($query);
if(mysql_num_rows($query_run)==0)
{
//start now
//start here
if (isset($_POST['submit']))
{
if(isset($_POST['a'.$id])) {
$status = $_POST['a'.$id];
if(!empty($status)){
if(($status == "present" || $status ==
"mc")){
$attend = 1;
}
else {
$attend = 0;
}
$query = "INSERT INTO attendance(ID,
birth_no, date, status, attend)
VALUES ('',
'$id','$date','$status','$attend')";
if($query_run = mysql_query($query)){
echo 'Insert attendance done';
}
else{
echo'Attendance not inserted.';
}
}
else{
echo 'Please enter all fields';
}
}
}
else
{
?>
<form action="addattend1.php" method = "POST">
<?php
$name = $row['name'];
?>
<tr>
<td><center><?php echo $date
?></center></td>
<td><center><?php echo $id
?></center></td>
<td><center><?php echo $name
?></center></td>
<td><center>
<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
</center>
</td>
</tr>
<?php
} // end else
?>
<?php //end here
}//end if
else
{
echo '<br><br>Attendance for date <font color="#FF0000"
><b><u>'.$date.'</u></b></font> is already
inserted!<br><br>';
}
}//end while
?>
</table>
<br /><br />
<center><input type="submit" name="submit"
value="Submit"></center><br /><br />
</form> <!-- end the form here -->
<?php
}//if not empty
else
{
?>
<br/
<font size="3" color color="#FF0000"><?php echo 'Please pick a
date first before proceed!' ?> </font><br>
<?php
}
}//if isset date
else
{
?><br/><br/>
<form action="addattend.php" method = "POST">
Date :<br><br ><input type="date" name = "date">
<input type="submit" value="Submit"><br /><br />
</form> <?php
}
As what you can see in above picture, "Attendance for date is already
inserted" is appeared twice since there are 2 students. If got 5 students,
the string will appear 5 times and so on. What i really want is, I want it
to appear only once and table with submit button will not display there.
Please help me. Thank you.
No comments:
Post a Comment