index.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. include_once "../../include/DB.php";
  3. $TotalRechargedSwapCount=0;
  4. $UsedRechargedSwapCount=0;
  5. $AvailableRechargedSwapCount=0;
  6. $SwapRechargeID="";
  7. if (isset($_POST["TotalRechargedSwapCount"]) && !empty($_POST["TotalRechargedSwapCount"])) {
  8. $TotalRechargedSwapCount=$_POST["TotalRechargedSwapCount"];
  9. }
  10. if (isset($_POST["UsedRechargedSwapCount"]) && !empty($_POST["UsedRechargedSwapCount"])) {
  11. $UsedRechargedSwapCount=$_POST["UsedRechargedSwapCount"];
  12. }
  13. if (isset($_POST["AvailableRechargedSwapCount"]) && !empty($_POST["AvailableRechargedSwapCount"])) {
  14. $AvailableRechargedSwapCount=$_POST["AvailableRechargedSwapCount"];
  15. }
  16. if (isset($_POST["SwapRechargeID"]) && !empty($_POST["SwapRechargeID"])) {
  17. $SwapRechargeID=$_POST["SwapRechargeID"];
  18. }
  19. $SwapRechargeUpdateSql = "UPDATE swaprecharge SET TotalRechargedSwapCount='$TotalRechargedSwapCount',UsedSwapCount='$UsedRechargedSwapCount',AvailableSwapCount='$AvailableRechargedSwapCount' WHERE SwapRechargeID='$SwapRechargeID'";
  20. $SwapRechargeUpdateResult = $conn->query($SwapRechargeUpdateSql);
  21. if ($SwapRechargeUpdateResult === TRUE) {
  22. $value = array(
  23. "SwapRechargeID"=>(int)$SwapRechargeID,
  24. "TotalRechargedSwapCount"=>(int)$TotalRechargedSwapCount,
  25. "UsedRechargedSwapCount"=>(int)$UsedRechargedSwapCount,
  26. "AvailableRechargedSwapCount"=>(int)$AvailableRechargedSwapCount,
  27. "Message"=>"Swap recharge data saved successfully",
  28. );
  29. // Use json_encode() function
  30. $json = json_encode($value);
  31. }else {
  32. http_response_code(404);
  33. $errorMesage= $conn->error;
  34. // Declare an array with error message
  35. $value = array(
  36. "Message"=>"Something went wrong",
  37. "Error"=>$errorMesage
  38. );
  39. // Use json_encode() function
  40. $json = json_encode($value);
  41. }
  42. // Display the output
  43. echo ($json);
  44. $conn->close();