-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.php
More file actions
43 lines (36 loc) · 1.12 KB
/
delete.php
File metadata and controls
43 lines (36 loc) · 1.12 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
<?php
include 'src/Connection.php'; // include Connection file
// Headers
header('Access-control-Allow-Origin:*');
header('Content-type:application/json');
header('Access-Control-Allow-Methods:DELETE');
header('Access-Control-Allow-Headers:Content-Type,Access-Control-Allow-Headers,Authorisation,X-Requested-With');
// Recive data from api url
$data = json_decode(file_get_contents("php://input"));
//table name
$table = 'student';
// Cheak if id is given or not
if(isset($data->id))
{
// prepare sql query to add data into the database
$query = $Conn->prepare("DELETE FROM $table WHERE id = ?");
$query->bind_param("i", $data->id);
$run = $query->execute(); // execute the query
if($run) // check if sql query run succesfully in the database
{
echo json_encode(['status'=>'success', 'msg'=>'deleted successfully']);
http_response_code(200);
}
else
{
echo json_encode(['status'=>'failed']);
http_response_code(404);
}
}
else
{
// if id not passed
echo json_encode(["status"=>"failed", "massage"=>"id not given"]);
http_response_code(404);
}
?>