<?php
require('connect.php');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST');  


$response = "";
$row = json_decode($_POST['data'], true);
$q = "SELECT id FROM control_form WHERE id=".$row['id'];
$r = mysqli_query($dbC, $q);
$nr = mysqli_num_rows($r);

if($nr==0){
    $qry = "INSERT INTO control_form SET ";
} else {
    $qry = "UPDATE control_form SET ";
}
	foreach ($row as $head => $val) {
	    if($head=='flag' || $head=='edit'){
	        continue;
	    } elseif($head=='id'){
	        $id = $val;
	        $qry.="id='".$val."',";
	    } elseif($head=='rcheck') {
	        $qry.=$head."='".$val."'";
	    } else{
	        $qry.=$head."='".$val."',";
	    }
	}
if($nr==1){
    $qry.= " WHERE id='".$id."'";
}
    
	if(mysqli_query($dbC, $qry)){
	    $response.=$id.": Success.<br />";
	} else {
	    $response.=$id.": Error(".mysqli_error($dbC).")<br />";
	   //$response.=$qry;
	}


echo $response;


?>