-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapi-delete.php
40 lines (27 loc) · 1.07 KB
/
api-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
<?php
header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Mehtods: DELETE");
header("Access-Control-Allow-Headers:Access-Control-Allow-Mehtods,Content-Type,Access-Control-Allow-Mehtods,Authorization,X-Requested-With");
/* use id for delete record
{
"sid": 2
}*/
//json format data converted to associative array
$data=json_decode(file_get_contents("php://input"),TRUE);
$student_id=$data['sid'];
include "config.php";
//Check student record exist or not if exists then we delete
$sql1="SELECT * FROM students WHERE id={$student_id}";
$result1=mysqli_query($conn,$sql1) or die("SQL Query Failed: Check record");
if(mysqli_num_rows($result1) > 0){
$sql="DELETE FROM students WHERE id={$student_id} ";
if(mysqli_query($conn,$sql)){
echo json_encode(array("message"=> "Student Record Deleted","status"=> TRUE));
}else{
echo json_encode(array("message"=> "Student Record Can't Deleted","status"=> FALSE));
}
}else{
echo json_encode(array("message"=> "Student Record does not exist","status"=> FALSE));
}
?>