-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.php
47 lines (37 loc) · 1.27 KB
/
delete.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
<?php
header('content-type: application/json; charset=utf-8');
header("access-control-allow-origin: *");
//Creating Array for JSON response
$response = array();
// Check if we got the field from the user
if (isset($_GET['id'])) {
$id = $_GET['id'];
// Include data base connect class
$filepath = realpath (dirname(__FILE__));
require_once($filepath."/db_connect.php");
// Connecting to database
$db = new DB_CONNECT();
// Fire SQL query to delete weather data by id
$result = mysql_query("DELETE FROM weather WHERE id = $id");
// Check for succesfull execution of query
if (mysql_affected_rows() > 0) {
// successfully deleted
$response["success"] = 1;
$response["message"] = "Data successfully deleted";
// Show JSON response
echo json_encode($response);
} else {
// no matched id found
$response["success"] = 0;
$response["message"] = "No weather data found by given id";
// Echo the failed response
echo json_encode($response);
}
} else {
// If required parameter is missing
$response["success"] = 0;
$response["message"] = "Parameter(s) are missing. Please check the request";
// Show JSON response
echo json_encode($response);
}
?>