Procházet zdrojové kódy

Add insert_list.php to Laura Branch

laura.gonzalez19 před 4 roky
rodič
revize
870fa2393d
1 změnil soubory, kde provedl 82 přidání a 0 odebrání
  1. 82
    0
      insert_list.php

+ 82
- 0
insert_list.php Zobrazit soubor

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