<?php 
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'restax');
define('DB_PASSWORD', 'restax');
define('DB_NAME', 'Restax'); 

$con = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
        $course_id=$request->getParsedBody()['course_id'];
		$dept_id=$request->getParsedBody()['dept_id'];
        $level_id=$request->getParsedBody()['level_id'];				
		$year=$request->getParsedBody()['year'];
		$term=$request->getParsedBody()['term'];
		$papers_shortcode=$request->getParsedBody()['papers_shortcode'];
		$paper_name=$request->getParsedBody()['paper_name'];
		$credits=$request->getParsedBody()['credits'];
		$type=$request->getParsedBody()['type'];
		
$response=array();

$sqll="(SELECT * FROM set_papers WHERE  papers_shortcode='$papers_shortcode' OR paper_name='$paper_name')";
$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 set_papers(course_id,dept_id,level_id,year,term,papers_shortcode,paper_name,credits,type) VALUES ('$course_id','$dept_id','$level_id','$year','$term','$papers_shortcode','$paper_name','$credits','$type')";

$res= $con->query($sql);
	
if($res==true)
{
		$data=array(
	"course_id"=>$course_id,
	"dept_id"=>$dept_id,
	"level_id"=>$level_id,	
	"year"=>$year,
	"term"=>$term,
	"papers_shortcode"=>$papers_shortcode,
	"paper_name"=>$paper_name,
	"credits"=>$credits,
	"type"=>$type,
	
	);
	    $message=$data;

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