12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
-
- #Connecting to the GroceryPolice Database
-
- $server = "localhost";
- $user = "GroceryPolice";
- $passwd = "P5B64tTUmGljk7cB";
- $db = "GroceryPolice";
-
- //Opens a new connection to the MySQL server
-
- $con= mysqli_connect($server,$user, $passwd, $db);
-
- /*
- //Receives JSON file from the app
-
- // Getting the received JSON into $Received_JSON variable.
- $Received_JSON = file_get_contents('php://input');
-
- // decoding the received JSON and store into $obj variable.
- $obj = json_decode($Received_JSON,true);
-
- // Populate from JSON $obj array and store into $user_name variable.
- $name_l = $obj['name_l'];
- $name_u = $obj['name_u'];
- $uid = $obj['uid'];
- $lid = $obj['lid'];
- */
-
- echo"<h1>Inserting Lists to Database</h1>"
-
- $name_l="Walgreens"
- $name_u="Petra Ma"
- $lid=1234
- $uid=2345
-
-
- //Checking if User already exist or not in MySQL database using SQL query.
- $CheckSQL = "SELECT L.name_l, L.name_u FROM List_Mngs L WHERE L.uid=$uid";
-
- // Executing SQL Query.
- $check = mysqli_fetch_array(mysqli_query($con,$CheckSQL));
-
- if(isset($check)){
-
- $Duplicate_user = 'User Already Exist, Please Try Again With Different User.';
-
- // Converting the message into JSON format.
- $Duplicate_user_Json = json_encode($Duplicate_user);
-
- // Echo, Printing the message on screen.
- echo $Duplicate_user_Json ;
-
- }
- else{
-
- // Creating SQL query and insert the record into MySQL database table if user dose not exist in database.
- //Change when Auto-Icrement is added
-
- $Sql_Query = "INSERT INTO List_Mngs(name_l,name_u,uid,lid) VALUES ('$name_l','$name_u','$uid','$lid')";
-
-
- if(mysqli_query($con,$Sql_Query)){
-
- // Show the success message.
- $MSG = 'List and User Registered Successfully' ;
-
- // Converting the message into JSON format.
- $json = json_encode($MSG);
-
- // Echo, Print the message on screen.
- echo '$json' ;
-
- }
- else{
-
- echo 'Try Again';
-
- }
- }
- mysqli_close($con);
- ?>
|