<?php
$con = mysqli_connect(localhost, Restax_final, Restax_final123, Restax_api_data);     
$set_papers_id=$request->getParsedBody()['set_papers_id'];
 $units=$request->getParsedBody()['units'];
  $course=$request->getParsedBody()['course'];
   $department=$request->getParsedBody()['department'];
    $level=$request->getParsedBody()['level'];
     $year=$request->getParsedBody()['year'];
      $term=$request->getParsedBody()['term'];
      $type=$request->getParsedBody()['type'];
$units_data = json_encode($units);
		
$response=array();

	// $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'";
	
	//anandh
// $sql="SELECT * FROM units WHERE set_papers_id='$set_papers_id'AND  course = '$course'AND department ='$department' AND  year= '$year'AND level = '$level'
// AND term= '$term'  AND type='$type'AND units ='$units' ";

$sql="SELECT * FROM units WHERE set_papers_id='$set_papers_id'";
// units error for final check

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

if ($result->num_rows > 0) 

{
      $sql="Update units 
   set units='$units_data' where set_papers_id=$set_papers_id";
  
   $res= $con->query($sql);
    
//   $sql="Update INTO units (set_papers_id,units,course,department,year,level,term,type) VALUES ('$set_papers_id','$units_data','$course','$department','$year','$level','$term','$type') where set_papers_id=$set_papers_id ";
    	
    	$response=array('status' => "false",'Message' => "already present inside");

echo json_encode($response); 
}
else
{
//anandh
$sql="INSERT INTO units (set_papers_id,units,course,department,year,level,term,type) VALUES ('$set_papers_id','$units_data','$course','$department','$year','$level','$term','$type')";


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

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


	    // $message=$data;

		

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

echo json_encode($response);
//anandh
}

  
    



?>