<?php
$con = mysqli_connect(localhost, Restax_final, Restax_final123, Restax_api_data);     

$course_id=$request->getParsedBody()['course_id'];
 $dept_id=$request->getParsedBody()['dept_id'];
 $level_id=$request->getParsedBody()['level_id'];
$range_in=$request->getParsedBody()['range_in'];
$grade=$request->getParsedBody()['grade'];
$type=$request->getParsedBody()['type_name'];
$state=$request->getParsedBody()['state_pf'];

	$get_range = explode("-",$range_in);
$response=array();

$sql12="SELECT * FROM set_grade WHERE course_id='$course_id' AND level_id='$level_id' AND dept_id='$dept_id' AND type='$type'AND range_start='$get_range[0]' AND range_end = '$get_range[1]' AND grade='$grade'";

$res12= $con->query($sql12);

if(mysqli_num_rows($res12) > 0)
{

$response2=array('status' => "true",'Message' => "Data Already Exits");

echo json_encode($response2);


}
else{
	// $sql= "UPDATE set_grade SET range_in='$range_in',grade='$grade',start_module='$start_module' WHERE course_id='$course_id'AND dept_id='$dept_id'AND level_id='$level_id'";

$sql="INSERT INTO set_grade(course_id,dept_id,level_id,range_start,range_end,grade,type,state) VALUES ('$course_id','$dept_id','$level_id','$get_range[0]','$get_range[1]','$grade','$type','$state')";


$res= $con->query($sql);

	$data=array('name' =>$grade, );


	    // $message=$data;

		

	$response=array('status' => "true",'Message' => "Data inserted successfully",$data);

echo json_encode($response);


}


?>