-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdel.php
48 lines (44 loc) · 1.14 KB
/
del.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
<?php
require_once('dbconfig.php');
error_reporting(E_ALL);
$conn = mysqli_connect('localhost', DB_USER, DB_PASS);
$res = mysqli_select_db($conn, DB_DB);
if (!$res) {
die(mysqli_error($conn));
}
$response = array();
if (isset($_REQUEST['id']) && $_REQUEST['id']) {
$id = intval($_REQUEST['id']);
}
if ($id) {
$query = 'DELETE FROM '.DB_TABLE." WHERE `id`=$id";
$result = mysqli_query($conn, $query);
if ($result) {
$response[] = "Deleted entry $id";
}
else {
header('500 Internal Server Error');
trigger_error($insert, E_USER_WARNING);
$code = mysqli_errno($conn);
$msg = mysqli_error($conn);
$response = array('code' => $code, 'msg' => $msg);
}
}
else {
header('400 Bad Request');
$code = '400';
$msg = 'Required parameter: id';
$response = array('code' => $code, 'msg' => $msg);
}
$json = json_encode($response);
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
header('Content-Length: '.strlen($json));
if (in_array('gzip', explode(',', $_SERVER['HTTP_ACCEPT_ENCODING']))) {
header('Content-Encoding: gzip');
echo gzencode($json);
}
else {
echo $json;
}
?>