-
Notifications
You must be signed in to change notification settings - Fork 0
/
leavegroup.php
36 lines (30 loc) · 1.12 KB
/
leavegroup.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
<?php
try{
//setting the second parameter to true to receive the data as an associative array
$received_data=json_decode(file_get_contents("php://input"),true);
$hiker_id=$received_data["userID"];
$group_id=$received_data["groupID"];
//CONNECTING TO THE DATABASE
$db_conn=mysqli_connect("localhost","root","","hiking");
if(!$db_conn){ echo '<h5 style="color:red;margin-left:200px;">Couldn"t Connect To Database<br>';}
$result=$db_conn->query("DELETE FROM groupmembers WHERE hikerID='$hiker_id' AND groupID='$group_id'");
if($result){
//inserted successfully send success response to client
$success_msg=["success"=>"group left successfully"];
header('Content-Type: application/json');
$jsonData=json_encode($success_msg);
//return the success json to the client
echo $jsonData;
}
else{
//send error response
$error_msg=["error"=>"couldn't delete data"];
header('Content-Type: application/json');
$jsonData=json_encode($error_msg);
echo $jsonData;
}
}
catch(Exception $error){
echo '<h5 style="color:red;margin-left:200px;">'.$error.'<br>';
}
?>