-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdel.php
More file actions
48 lines (43 loc) · 1.3 KB
/
Copy pathdel.php
File metadata and controls
48 lines (43 loc) · 1.3 KB
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(DB_ADDR, DB_USER, DB_PASS);
$res = mysqli_select_db($conn, DB_DB);
if (!$res) {
die(mysqli_error($conn));
}
$response = array();
$id = 0;
if (isset($_REQUEST['id']) && $_REQUEST['id']) {
$id = intval($_REQUEST['id']);
}
$subject = isset($_REQUEST['subject']) ? mysqli_real_escape_string($conn, $_REQUEST['subject']) : '';
if ($id) {
$where = "`id`=$id" . ($subject ? " AND `subject`='$subject'" : '');
$query = 'DELETE FROM '.DB_TABLE." WHERE $where";
$result = mysqli_query($conn, $query);
if ($result) {
$response[] = "Deleted entry $id";
}
else {
http_response_code(500);
trigger_error($query, E_USER_WARNING);
$code = mysqli_errno($conn);
$msg = mysqli_error($conn);
$response = array('code' => $code, 'msg' => $msg);
}
}
else {
http_response_code(400);
$response = array('code' => 400, 'msg' => 'Required parameter: id');
}
$json = json_encode($response);
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
if (!empty($_SERVER['HTTP_ACCEPT_ENCODING']) && stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) {
header('Content-Encoding: gzip');
$json = gzencode($json);
}
header('Content-Length: '.strlen($json));
echo $json;
?>