Нема описа

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. #Connecting to the GroceryPolice Database
  3. $server = "localhost";
  4. $user = "GroceryPolice";
  5. $passwd = "P5B64tTUmGljk7cB";
  6. $db = "GroceryPolice";
  7. //Opens a new connection to the MySQL server
  8. $con= mysqli_connect($server,$user, $passwd, $db);
  9. //Receives JSON file from the app
  10. // Getting the received JSON into $Received_JSON variable.
  11. $Received_JSON = file_get_contents('php://input');
  12. // decoding the received JSON and store into $obj variable.
  13. $obj = json_decode($Received_JSON,true);
  14. // Populate from JSON $obj array and store into $user_name variable.
  15. $name_p=$obj['name_p'];
  16. $bought_date=$obj['bought_date'];
  17. $expiration_date=$obj['expiration_date'];
  18. $type=$obj['type'];
  19. $lid=$obj['lid'];
  20. $quantity=$obj['quantity'];
  21. $renew=$obj['renew'];
  22. $notes=$obj['notes'];
  23. //Checking if User already exist or not in MySQL database using SQL query.
  24. $query ="INSERT INTO `Product`(`name_p`, `bought_date`, `expiration_date`, `type`, `quantity`, `renew`, `notes`, `lid`) VALUES ('$name_p','$bought_date','$expiration_date','$type',$quantity,$renew,'$notes',$lid)";
  25. // Executing SQL Query.
  26. if(empty($name_p) or empty($bought_date) or empty($expiration_date) or empty($type) or empty($lid) or empty($quantity) or empty($renew) or empty($notes)){
  27. $MSG = 'Field is empty. Enter information again...' ;
  28. // Converting the message into JSON format.
  29. $json = json_encode($MSG);
  30. // Echo, Print the message on screen.
  31. echo $json;
  32. }
  33. else{
  34. if(mysqli_query($con,$query)){
  35. // Show the success message.
  36. $MSG = 'Product Registered Successfully' ;
  37. // Converting the message into JSON format.
  38. $json = json_encode($MSG);
  39. echo $json;
  40. }
  41. else{
  42. $MSG ="Error. Try again" ;
  43. // Converting the message into JSON format.
  44. $json = json_encode($MSG);
  45. // Echo, Print the message on screen.
  46. echo $json;
  47. }
  48. }
  49. mysqli_close($con);
  50. ?>