<?
header('Access-Control-Allow-Origin: *');

//var_dump(json_decode(file_get_contents("php://input")));
$postData = json_decode(file_get_contents("php://input"));

//$mysqli = new mysqli("localhost", "afxtech1_myori", "myori2017", "afxtech1_myori");
include_once("db_connect.php");
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
} 



$query = "INSERT INTO reports_actions (id, officer, remark, action, status, photo1, photo2) VALUES ('" .$postData->id. "', '" .$postData->assignby. "', '" .$postData->arahan. "', '999', '0', null, null) ";
if ($mysqli->query($query) === TRUE) {}    

$query = "UPDATE reports SET officer = '" .$postData->officer. "', notes = '" .$postData->arahan. "', category = '" .$postData->kategori. "', assignby = '" .$postData->assignby. "', assigndt=now() WHERE status = '0' AND id = '" .$postData->id. "' ";

if ($mysqli->query($query) === TRUE) {
    echo "Record updated successfully";
    http_response_code(200);
} else {
    echo "Error updating record: " . $mysqli->error;
    http_response_code(401);
}

$mysqli->close();

?>