add.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. include_once "../../include/DB.php";
  3. $AssetID="";
  4. $AssetName="";
  5. $AssetCategoryID="";
  6. $IsInServiceCenter=1;
  7. if (isset($_POST["AssetID"]) && !empty($_POST["AssetID"])) {
  8. $AssetID=$_POST["AssetID"];
  9. }
  10. if (isset($_POST["AssetName"]) && !empty($_POST["AssetName"])) {
  11. $AssetName=$_POST["AssetName"];
  12. }
  13. if (isset($_POST["AssetCategoryID"]) && !empty($_POST["AssetCategoryID"])) {
  14. $AssetCategoryID=$_POST["AssetCategoryID"];
  15. }
  16. if (isset($_POST["IsInServiceCenter"]) && !empty($_POST["IsInServiceCenter"])) {
  17. $IsInServiceCenter=$_POST["IsInServiceCenter"];
  18. }
  19. $AssetInsertSql = "INSERT INTO asset(AssetID, AssetName, AssetCategoryID, IsInServiceCenter) VALUES ('$AssetID','$AssetName','$AssetCategoryID','$IsInServiceCenter')";
  20. $AssetInsertresult = $conn->query($AssetInsertSql);
  21. if ($AssetInsertresult === TRUE) {
  22. $value = array(
  23. "AssetID"=>$AssetID,
  24. "AssetName"=>$AssetName,
  25. "AssetCategoryID"=>$AssetCategoryID,
  26. "IsInServiceCenter"=>$IsInServiceCenter,
  27. "Message"=>"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. $value = array(
  35. "Message"=>"Something went wrong",
  36. "Error"=>$errorMesage
  37. );
  38. // Use json_encode() function
  39. $json = json_encode($value);
  40. }
  41. // Display the output
  42. echo ($json);
  43. $conn->close();