-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
111 lines (83 loc) · 2.85 KB
/
index.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
#VT
$db = new PDO("mysql:host=localhost;dbname=api;charset=utf8","root","");
$tablename = "todo";
#FUNC
function input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if (isset($_GET["api_key"])) {
$api_key = input($_GET["api_key"]);
if ($api_key == "cyprs") {
// API KEY TRUE
if (isset($_GET["getall"])) {
$fetch_all = $db->prepare("SELECT * FROM $tablename");
$fetch_all->execute();
$fetch = array();
while($row=$fetch_all->fetch(PDO::FETCH_ASSOC)){
$fetch['jsondata'][] = $row;
}
echo json_encode($fetch);
}
if (isset($_GET["get_status_one"])) {
$fetch_all = $db->prepare("SELECT * FROM $tablename WHERE status = 1");
$fetch_all->execute();
$fetch = array();
while($row=$fetch_all->fetch(PDO::FETCH_ASSOC)){
$fetch['jsondata'][] = $row;
}
echo json_encode($fetch);
}
if (isset($_GET["getone_id"])) {
$getone_id = input($_GET["getone_id"]);
$getone_id_fetch = $db->prepare("SELECT * FROM $tablename WHERE id = '$getone_id'");
$getone_id_fetch->execute();
$fetch = array();
while($row=$getone_id_fetch->fetch(PDO::FETCH_ASSOC)){
$fetch['jsondata'][] = $row;
}
echo json_encode($fetch);
}
if (isset($_GET["getone_name"])) {
$getone_name = input($_GET["getone_name"]);
$getone_name_fetch = $db->prepare("SELECT * FROM $tablename WHERE name = '$getone_name'");
$getone_name_fetch->execute();
$fetch = array();
while($row=$getone_name_fetch->fetch(PDO::FETCH_ASSOC)){
$fetch['jsondata'][] = $row;
}
echo json_encode($fetch);
}
if (isset($_GET["update_status_id"])) {
$update_status_id = input($_GET["update_status_id"]);
$update = $db->prepare("UPDATE $tablename SET status = ? WHERE id = ?");
$update->execute(array("1", $update_status_id));
$update_select = $db->prepare("SELECT * FROM $tablename WHERE id = $update_status_id");
$update_select->execute();
$fetch = array();
while($row=$update_select->fetch(PDO::FETCH_ASSOC)){
$fetch['jsondata'][] = $row;
}
echo json_encode($fetch);
}
if (isset($_GET["delete_id"])) {
$delete_id = input($_GET["delete_id"]);
$delete = $db->exec("DELETE FROM $tablename WHERE id = $delete_id");
echo "true";
}
if (isset($_GET["name"])) {
$name = input($_GET["name"]);
$query = $db->prepare("INSERT INTO $tablename (name) VALUES (?)");
$query->execute(array($name));
echo "Success";
}
}else {
echo "API KEY!";
}
}else {
echo "API KEY!";
}
?>