forked from CS315Allstars/inventory_management_simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RPGservices.php
81 lines (68 loc) · 1.74 KB
/
RPGservices.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
session_start();
//Allows CORS
//
header("Access-Control-Allow-Origin: *");
$url='localhost';
$database='RPGtracker';
$username='root' ;
$password='';
$conn=mysqli_connect($url,$username,$password,$database);
if(!$conn){
die('Connection failed'.$conn->connect_error);
}
$method=$_SERVER['REQUEST_METHOD'];
if($method=="GET"){
$result=mysqli_query($conn,$_SESSION['query']);
$rows=array();
if(mysqli_num_rows($result)>0){
while($r=mysqli_fetch_assoc($result)){
array_push($rows,$r);
}
print json_encode($rows);
}else{
echo "No data";
}
}
else if($method=="POST"){
/*$name=$_POST['partyName'];
$sql_insert="INSERT INTO party(partyName) VALUES ('$name')";
if(mysqli_query($conn,$sql_insert)){
echo "Items succesfully added to the database.";
}
else{
echo "ERROR: $sql_insert did not run. ".mysqli_error($conn);
}*/
$sql_insert=$_POST['vName'];
// For Debugging
// echo "SQL: ".$sql_insert;
$result=mysqli_query($conn,$sql_insert);
// For Debugging
// if($conn){
// echo "conn succesful";
// }
// else{
// echo "conn failed";
// }
// if($result){
// echo "result succesful";
// }
// else{
// echo "result failed";
// }
if(substr($sql_insert,0,6)=='SELECT'){
//echo "not inserting into table";
if(mysqli_num_rows($result)>0){
while($row=mysqli_fetch_assoc($result)){
if(substr_count($sql_insert, "party")>0){
echo $row['partyName'];
}
elseif (substr_count($sql_insert, "characters")>0) {
echo $row['charName'];
}
}
}
}
}
mysqli_close($conn);
?>