<?php 
session_start();
include 'dbc.php';
date_default_timezone_set("Asia/Karachi");
$today=$_POST["exam_date"];
$userid=$_SESSION["userid"];
$exam_name=$_POST["exam_name"];
$cls_sec=$_POST["cls_sec"];
$sess1=$_POST["sess1"];
$class_name=$_POST["class_name"];
$mrk=$_POST["mrk"];
$camp=$_POST["camp"];
$noq=$_POST["noq"];

/*$duplicate=mysqli_query($conn,"select * from exam_save where cls_sec='$cls_sec' and class_name='$class_name' and exam_name='$exam_name' and date='$today' and sess1='$sess1'");
if (mysqli_num_rows($duplicate)>0)
{
header("Location: Genrate_Exam.php?message=Exam Name Already Exist.");
}
else{*/

$sqlchallan = "SELECT * FROM admission where mclass='$class_name' and user_id='$camp'";
$resultchallan=$conn->query($sqlchallan);
while($rowchallan = $resultchallan->fetch_assoc())
 
  {
  $std_rollno=$rowchallan["std_rollno"];
$std_name=$rowchallan['std_name'];
$father_name=$rowchallan['father_name'];
$cell_1=$rowchallan['cell_1'];
$pwd=$rowchallan['pwd'];
$user_id=$rowchallan['user_id'];
$tmark=0;

$i = 1;
while ($i < $noq) {
$sqlexam = "SELECT * FROM qpaper where class_name='$class_name' and cls_sec='$cls_sec'";
$exam=$conn->query($sqlexam);
while($rowexam = $exam->fetch_assoc())
 
  {
  	if ($i <= $noq){
$qno=$rowexam["id"];
$qname=$rowexam['notice'];
$option1=$rowexam['option1'];
$option2=$rowexam['option2'];
$option3=$rowexam['option3'];
$option4=$rowexam['option4'];
$ans=$rowexam['ans'];
$sql = "Insert into exam_paper (id,date,sess1,exam_name,class_name,cls_sec,std_rollno,std_name,father_name,cell_1,qno,qname,mrk,option1,option2,option3,option4,ans,pwd,user_id) values (null,'$today','$sess1','$exam_name','$class_name','$cls_sec','$std_rollno','$std_name','$father_name','$cell_1','$qno','$qname','$mrk','$option1','$option2','$option3','$option4','$ans','$pwd','$user_id')";
$conn->query($sql);
$tmark= $tmark + $mrk;

++$i;
}
}
}
//mysql_query($sql) or die("Error : " . mysql_error());
$sql = "Insert into exam_save (id,date,sess1,exam_name,class_name,cls_sec,std_rollno,std_name,father_name,cell_1,tmark,omark,per,grd,status,pwd,user_id) values (null,'$today','$sess1','$exam_name','$class_name','$cls_sec','$std_rollno','$std_name','$father_name','$cell_1','$tmark','0','0','0','Open','$pwd','$user_id')";
$conn->query($sql);

 }
header("location:Genrate_Exam.php");
//}

/*$sql="Select * from agents where userid='$user_id'";
$data=mysql_query($sql) or die ("Error:" . mysql_error());
$userdata=mysql_fetch_array($data);
$email=$userdata["e_mail"];
mail($email . ",info@lalburj.com","Candidate Information","Candidate Data Posted Successfully","Passport No:" . $app_pp_no . " of " . $app_name . "Has been Posted Successfully By:" . $_SESSION["userid"]);*/
?>
