query($SwapInsertSql); if ($SwapInsertresult === TRUE) { $ReferPostData = array( 'SwapReferID' => $SwapReferID, 'TotalReferdSwapCount' => $TotalReferdSwapCount, 'UsedReferdSwapCount' => $UsedReferdSwapCount, 'AvailableReferdSwapCount' => $AvailableReferdSwapCount, ); $ReferURL = "http://localhost/cygnusa/batterySwap/api/Admin/Refer"; $ReferCURL = curl_init($ReferURL); curl_setopt($ReferCURL, CURLOPT_HEADER, false); curl_setopt($ReferCURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($ReferCURL, CURLOPT_POST, true); curl_setopt($ReferCURL, CURLOPT_POSTFIELDS, $ReferPostData); $ReferJsonResponse = curl_exec($ReferCURL); $value = array( "RiderID"=>$RiderID, "ReturnBatteryID"=>$ReturnBatteryID, "SwapBatteryID"=>$SwapBatteryID, "Refer"=>$ReferJsonResponse, "Message"=>"Swap Data saved 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();