<?php 
session_start();
include 'dbc.php';

date_default_timezone_set("Asia/Karachi");

$userid=$_SESSION["userid"];
$status=$_POST["status"];

$class_name=$_POST["class_name"];
$date=$_POST["date"];
$month_name=$_POST["month_name"];
$sess1=$_POST["sess1"];
   $sqlchallan1 = "SELECT * FROM attendence where class_name='$class_name' and date='$date' and user_id='$userid'";
$resultchallan1=$conn->query($sqlchallan1);
while($rowchallan1 = $resultchallan1->fetch_assoc())
 
  {
  $tatt = $tatt + 1;
  }
  if ($tatt < 1)
  {
  $sqlchallan = "SELECT * FROM admission where class_name='$class_name' and status='Active' and user_id='$userid'";
$resultchallan=$conn->query($sqlchallan);
while($rowchallan = $resultchallan->fetch_assoc())
 
  {
  $adm_no=$rowchallan["adm_no"];
$portal_id=$rowchallan['portal_id'];
$std_name=$rowchallan['std_name'];
$fname=$rowchallan['fname'];
$cls_sec=$rowchallan['cls_sec'];
$cell_1=$rowchallan['cell_1'];
$rfid=$rowchallan['rfid'];


$sql = "Insert into attendence (id,date,rollno,stdname,fname,class_name,cls_sec,status,month_name,cell,user_id,sess1,rfid,portal_id) values (null,'$date','$adm_no','$std_name','$fname','$class_name','$cls_sec','$status','$month_name','$cell_1','$userid','$sess1','$rfid','$portal_id')";
$conn->query($sql);

 }
echo "Attendance Genrate Sucessfully";
}
else
{
echo "Attendance Already Genrate Today";
}
?>
<a href="Genrate_Attendance.php">Back</a>