Нема описа

insert_list.php 1.9KB

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. /*
  10. //Receives JSON file from the app
  11. // Getting the received JSON into $Received_JSON variable.
  12. $Received_JSON = file_get_contents('php://input');
  13. // decoding the received JSON and store into $obj variable.
  14. $obj = json_decode($Received_JSON,true);
  15. // Populate from JSON $obj array and store into $user_name variable.
  16. $name_l = $obj['name_l'];
  17. $name_u = $obj['name_u'];
  18. $uid = $obj['uid'];
  19. $lid = $obj['lid'];
  20. */
  21. echo"<h1>Inserting Lists to Database</h1>"
  22. $name_l="Walgreens"
  23. $name_u="Petra Ma"
  24. $lid=1234
  25. $uid=2345
  26. //Checking if User already exist or not in MySQL database using SQL query.
  27. $CheckSQL = "SELECT L.name_l, L.name_u FROM List_Mngs L WHERE L.uid=$uid";
  28. // Executing SQL Query.
  29. $check = mysqli_fetch_array(mysqli_query($con,$CheckSQL));
  30. if(isset($check)){
  31. $Duplicate_user = 'User Already Exist, Please Try Again With Different User.';
  32. // Converting the message into JSON format.
  33. $Duplicate_user_Json = json_encode($Duplicate_user);
  34. // Echo, Printing the message on screen.
  35. echo $Duplicate_user_Json ;
  36. }
  37. else{
  38. // Creating SQL query and insert the record into MySQL database table if user dose not exist in database.
  39. //Change when Auto-Icrement is added
  40. $Sql_Query = "INSERT INTO List_Mngs(name_l,name_u,uid,lid) VALUES ('$name_l','$name_u','$uid','$lid')";
  41. if(mysqli_query($con,$Sql_Query)){
  42. // Show the success message.
  43. $MSG = 'List and User Registered Successfully' ;
  44. // Converting the message into JSON format.
  45. $json = json_encode($MSG);
  46. // Echo, Print the message on screen.
  47. echo '$json' ;
  48. }
  49. else{
  50. echo 'Try Again';
  51. }
  52. }
  53. mysqli_close($con);
  54. ?>