"fail", "error" => "Access denied")); exit; } if ($_SERVER['REQUEST_METHOD'] != "POST") { $result = array ( "result" => "fail", "error" => "Only POST requests are accepted" ); echo json_encode($result); exit; } try { $json = file_get_contents('php://input'); $data = json_decode($json); if (is_null ($data)) { $result = array ( "result" => "fail", "error" => 'Invalid format, expecting "{id: {user ID}, first_name: "{first name}", surname: "{surname}"}' ); echo json_encode($result); exit; } } catch (Exception $e) { $result = array ( "result" => "fail", "error" => 'Invalid format, expecting \"{id: {user ID}, first_name: "{first name}", surname: "{surname}\"}' ); echo json_encode($result); exit; } $query = "UPDATE users SET first_name = '" . $data->first_name . "', last_name = '" . $data->surname . "' where user_id = " . $data->id . ""; $result = mysqli_query($GLOBALS["___mysqli_ston"], $query ) or die( '
' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '' ); print json_encode (array ("result" => "ok")); exit; ?>