query($SwapRechargeUpdateSql); if ($SwapRechargeUpdateResult === TRUE) { $value = array( "SwapRechargeID"=>(int)$SwapRechargeID, "TotalRechargedSwapCount"=>(int)$TotalRechargedSwapCount, "UsedRechargedSwapCount"=>(int)$UsedRechargedSwapCount, "AvailableRechargedSwapCount"=>(int)$AvailableRechargedSwapCount, "Message"=>"Swap recharge 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();