123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
-
- $server = "localhost";
- $user = "GroceryPolice";
- $passwd = "P5B64tTUmGljk7cB";
- $db = "GroceryPolice";
-
- //Opens a new connection to the MySQL server
-
- $con= mysqli_connect($server,$user, $passwd, $db);
-
-
- // 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 User name from JSON $obj array and store into $user_name variable.
- $name_l = $obj['name_l'];
-
- // Populate User email from JSON $obj array and store into $user_email variable.
- $store = $obj['store'];
-
- // Populate Password from JSON $obj array and store into $user_password variable.
- $uid = $obj['uid'];
-
-
-
-
- //Checking User entered Email is already exist or not in MySQL database using SQL query.
- $CheckSQL = "SELECT * FROM `List` L WHERE L.uid=$uid and L.name_l='$name_l'";
-
- // Executing SQL Query.
- $check = mysqli_fetch_array(mysqli_query($con,$CheckSQL));
-
-
- // Executing SQL Query.
- if(empty($name_l) or empty($store) or empty($uid)){
-
- $MSG = 'Field is empty. Enter information again...' ;
-
- // Converting the message into JSON format.
- $json = json_encode($MSG);
-
- // Echo, Print the message on screen.
-
- echo $json;
-
- }
-
- else{
- if(isset($check)){
-
- $Duplicate_user = 'List Name Already Exist, Please Try Again';
-
- // 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 email dose not exist in database.
- $Sql_Query = "INSERT INTO `List`(`name_l`, `store`, `uid`) VALUES ('$name_l','$store','$uid')";
-
-
- if(mysqli_query($con,$Sql_Query)){
-
- // Show the success message.
- $MSG = 'List Registered Successfully' ;
-
- // Converting the message into JSON format.
- $json = json_encode($MSG);
-
- echo $json;
- }
- else{
- $MSG='Not Registered Correctly';
- $json = json_encode($MSG);
- echo $json;
-
- }
- }
- }
- mysqli_close($con);
- ?>
|