Parcourir la source

Add insert_l.php to master branch

laura.gonzalez19 il y a 4 ans
Parent
révision
8c3be5b798
1 fichiers modifiés avec 90 ajouts et 0 suppressions
  1. 90
    0
      insert_l.php

+ 90
- 0
insert_l.php Voir le fichier

@@ -0,0 +1,90 @@
1
+<?php
2
+
3
+$server = "localhost";
4
+$user = "GroceryPolice";
5
+$passwd = "P5B64tTUmGljk7cB";
6
+$db = "GroceryPolice";
7
+
8
+//Opens a new connection to the MySQL server
9
+
10
+$con= mysqli_connect($server,$user, $passwd, $db);
11
+ 
12
+
13
+// Getting the received JSON into $Received_JSON variable.
14
+$Received_JSON = file_get_contents('php://input');
15
+ 
16
+// decoding the received JSON and store into $obj variable.
17
+ $obj = json_decode($Received_JSON,true);
18
+ 
19
+ // Populate User name from JSON $obj array and store into $user_name variable.
20
+ $name_l = $obj['name_l'];
21
+ 
22
+ // Populate User email from JSON $obj array and store into $user_email variable.
23
+ $store = $obj['store'];
24
+ 
25
+ // Populate Password from JSON $obj array and store into $user_password variable.
26
+ $uid = $obj['uid'];
27
+ 
28
+ 
29
+ 
30
+ 
31
+ //Checking User entered Email is already exist or not in MySQL database using SQL query.
32
+ $CheckSQL = "SELECT * FROM `List` L WHERE L.uid=$uid and L.name_l='$name_l'";
33
+ 
34
+ // Executing SQL Query.
35
+ $check = mysqli_fetch_array(mysqli_query($con,$CheckSQL));
36
+ 
37
+ 
38
+  // Executing SQL Query.
39
+if(empty($name_l) or empty($store) or empty($uid)){ 
40
+
41
+	$MSG = 'Field is empty. Enter information again...' ;
42
+	 
43
+	 // Converting the message into JSON format.
44
+	 $json = json_encode($MSG);
45
+	 
46
+	 // Echo, Print the message on screen.
47
+
48
+	echo $json;
49
+ 
50
+ }
51
+ 
52
+else{
53
+	if(isset($check)){
54
+	 
55
+		 $Duplicate_user = 'List Name Already Exist, Please Try Again';
56
+		 
57
+		 // Converting the message into JSON format.
58
+		 $Duplicate_user_Json = json_encode($Duplicate_user);
59
+		 
60
+		 // Echo, Printing the message on screen.
61
+		 echo $Duplicate_user_Json ; 
62
+	 
63
+	 }
64
+	 else{
65
+	 
66
+		 // Creating SQL query and insert the record into MySQL database table if email dose not exist in database.
67
+		 $Sql_Query = "INSERT INTO `List`(`name_l`, `store`, `uid`) VALUES ('$name_l','$store','$uid')";
68
+		 
69
+		 
70
+		 if(mysqli_query($con,$Sql_Query)){
71
+		 
72
+			 // Show the success message.
73
+			 $MSG = 'List Registered Successfully' ;
74
+			 
75
+			 // Converting the message into JSON format.
76
+			 $json = json_encode($MSG);
77
+			 
78
+			 echo $json;
79
+		 }
80
+		 else{
81
+			$MSG='Not Registered Correctly'; 
82
+			$json = json_encode($MSG);
83
+			echo $json;
84
+
85
+			 }
86
+		}
87
+}
88
+ mysqli_close($con);
89
+?>
90
+