i was testing for an attendance website, logging attendance on different dates (manually changing the date on my device) i have a status column 1 for present and 0 for absent. when i log an attendance where some are absent, the status column on that date are reflected correctly but when I log an attendance where all are present, the status column values on all dates (including the ones with '0') are all changed to '1'. below is the code for the save
if(isset($_POST['save'])){
$studentNo=$_POST['studentNo'];
$check=$_POST['check'];
$N = count($studentNo);
$status = "";
$qurty=mysqli_query($conn,"select * from tblattendance where subject = '$id' and date = '$dateTaken' and status = '1'");
$count = mysqli_num_rows($qurty);
if($count > 0){
$statusMsg = "<div class='alert alert-danger' style='margin-right:700px;'>Attendance has been taken for today!<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button></div>";
}else
{
for($i = 0; $i < $N; $i++)
{
$studentNo[$i];
if(isset($check[$i]))
{
$qquery=mysqli_query($conn,"update tblattendance set status='1' where studentNo= '$check[$i]'");
if ($qquery) {
$statusMsg = "<div class='alert alert-success' style='margin-right:700px;'>Attendance Taken Successfully!<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button></div>";
}
else
{
$statusMsg = "<div class='alert alert-danger' style='margin-right:700px;'>An error Occurred!</div>";
}
}
}
}
}
$query = "SELECT tblsection.section,tblassignteach.secId,tblclass.className,tblsubject.subject,tblstudents.secId,tblstudents.studentNum,tblstudents.firstName,tblstudents.lastName,tblstudents.mname,tblstudents.sex,tblstudents.classId FROM tblstudents
INNER JOIN tblassignteach ON tblassignteach.secId = tblstudents.secId
INNER JOIN tblsection ON tblsection.Id = tblstudents.secId
INNER JOIN tblclass ON tblclass.Id = tblstudents.classId
INNER JOIN tblclassarms ON tblclassarms.Id = tblassignteach.classArmId
WHERE tblassignteach.subject='$id'";
$rs = mysqli_query($conn, $query);
$num = $rs->num_rows;
$sn=0;
$status="";
if($num > 0)
{
while ($rows = $rs->fetch_assoc())
{
$sn = $sn + 1;
echo"
<tr>
<td><input name='check[]' type='checkbox' value=".$rows['studentNum']." class='form-control'></td>
<td>".$sn."</td>
<td>".$rows['studentNum']."</td>
<td>".$rows['lastName']."</td>
<td>".$rows['firstName']."</td>
<td>".$rows['mname']."</td>
<td>".$rows['sex']."</td>
<td>".$rows['className']."</td>
<td>".$rows['section']."</td>
<td>".$rows['subject']."</td>
</tr>";
echo "<input name='studentNo[]' value=".$rows['studentNum']." type='hidden' class='form-control'>";
}
}
$qurty=mysqli_query($conn,"SELECT * from tblattendance where subject= '$id' and dateTimeTaken = '$dateTaken'");
$count=mysqli_num_rows($qurty);
if($count == 0){
$qus=mysqli_query($conn,"SELECT tblstudents.studentNum,tblassignteach.subject from tblstudents
inner join tblassignteach on tblassignteach.secId = tblstudents.secId
where tblassignteach.subject= '$id'");
while ($ros = $qus->fetch_assoc())
{
$qquery=mysqli_query($conn,"INSERT into tblattendance(studentNo,subject,sessionTermId,status,dateTimeTaken,timeTaken)
VALUES('$ros[studentNum]','$id','$sessionTermId','0', '$dateTaken', '$ttimeTaken')");
}
i'm wondering why all the values in all logged dates in the db are changed to '1' and if there is a way to fix this. if you need anything else, please dont hesitate to let me know and I really appreciate all the help i can get. thank you in advance!
The first thing I noticed was the lack of dots next to the php variables.