query($ServiceCheckSQL); if ($ServiceCheckResult!== false && $ServiceCheckResult->num_rows > 0) { while($ServiceCheckRow = $ServiceCheckResult->fetch_assoc()) { $ServiceHistoryID = $ServiceCheckRow["ServiceHistoryID"]; $ServiceUpdateSQL = "UPDATE servicehistory servicehistory SET servicehistory.InWard='$currentDateTime',isServiced='1' WHERE servicehistory.ServiceHistoryID='$ServiceHistoryID'"; $ServiceUpdateResult = $conn->query($ServiceUpdateSQL); if ($ServiceUpdateResult === TRUE) { $value = array( "Message"=>"Service updated successfully", ); // Use json_encode() function $json = json_encode($value); }else { http_response_code(404); $errorMesage= $conn->error; // Declare an array with error message $value = array( "Message"=>"Something went wrong", "Error"=>$errorMesage ); // Use json_encode() function $json = json_encode($value); } } }else { $ServiceInsertSQL = "INSERT INTO servicehistory(AssetID) VALUES ('$AssetID')"; $ServiceInsertResult = $conn->query($ServiceInsertSQL); if ($ServiceInsertResult === TRUE) { $value = array( "Message"=>"Service insert successfully", ); // Use json_encode() function $json = json_encode($value); }else { http_response_code(404); $errorMesage= $conn->error; // Declare an array with error message $value = array( "Message"=>"Something went wrong", "Error"=>$errorMesage ); // Use json_encode() function $json = json_encode($value); } } // Display the output echo ($json); $conn->close();