<?php

$con = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

  $course_id=$request->getParsedBody()['course_id'];
		$season_id=$request->getParsedBody()['season_id'];  
  $examname=$request->getParsedBody()['examname'];
		$examtype=$request->getParsedBody()['examtype'];       
     	$exam_start="0";	
			    	
                        
$response=array();


$sqll="(SELECT * FROM Exams WHERE  examname='$examname' )";
$res= $con->query($sqll);
if($res->num_rows>0)
{
$response1=array('status' => "true",'Message' => "data already exist");
echo json_encode($response1);
}

else{
$sql="INSERT INTO Exams(course_id,season_id,examname,examtype,exam_start) 
VALUES ('$course_id','$season_id','$examname','$examtype','$exam_start')";

$res= $con->query($sql);
	
if($res==true)
{
		$data=array(
	"course_id"=>$course_id,
	"season_id"=>$season_id,
	"examname"=>$examname,
	"examtype"=>$examtype,
	
	);
	    $message=$data;
	

	
	$response=array('status' => "true",'Message' => "Data inserted successfully",'Exams' => $message);
echo json_encode($response);
        
}
        else{
          $response=array('status' => "false",'Message' => " insert data failed");
         echo json_encode($response);
        }   
		
}

?>