<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
//echo "<script>alert('PROCESSING...');</script>";
include "./form.php";
include "./connector.php";

if(isset($_REQUEST['admission_no'])){
	$type = $_REQUEST;
	$a=$type;
	if(is_array($a)){
	$value_name = array_keys($a);
	$posts = $value_name;
		foreach ($posts as $value) {///
			$name = $value;	
			$$value = mysqli_real_escape_string($form2->con(), $type[$name]);
			$value = mysqli_real_escape_string($form2->con(), $type[$name]);
		}
	}

//////////

$created = time();
$result_id = "$admission_no-$session-$term";
$pin = base64_encode($admission_no);
$last_update = "";

$form2->run_query("DELETE FROM `online_result` WHERE result_id='$admission_no-$session-$term'");

	$sql = "INSERT INTO `online_result` (`admission_no`, `result_id`, `student_name`, `result_data`, `session`,`class`,`arm`, `term`, `pin`, `last_update`, `created`) VALUES ('$admission_no', '$result_id', '$student_name', '$result_data', '$session', '$sclass', '$arm', '$term', '$pin', '$last_update', '$created');";

	if($form2->run_query($sql)){
		echo "<script>alert('Successfully Uploaded $term result for $admission_no $student_name with pin $pin');close_dialog();</script>";
	}

}else{
	
	echo "<script>alert('Not uploaded');</script>";
}


?>