-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
48 lines (40 loc) · 1.19 KB
/
api.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
48
<?php
header('Access-Control-Allow-Origin: *');
header("Content-Type:application/json;charset-UTF-8");
require_once("config/connection.php");
// print_r($_SERVER);
if($_SERVER['REQUEST_METHOD']=="POST"){
$name=$_POST['name'];
$lat=$_POST['lat'];
$lon=$_POST['lon'];
$company=$_POST['company'];
$id=$_POST['customer_id'];
$address=$_POST['address'];
$sql="INSERT into garbagedataset (name,lat,lon,company,customer_id,status,address) VALUES('$name','$lat','$lon','$company','$id','0','$address')";
$res=mysqli_query($conn,$sql);
if(!$res){
echo mysqli_error($conn);
}else{
echo 1;
}
}else if($_SERVER['REQUEST_METHOD']=="GET"){
$company=$_GET['company'];
$sql="SELECT * from garbagedataset where status=0";
$res=mysqli_query($conn,$sql);
if(!$res){
echo mysqli_error($conn);
}else{
$row=mysqli_fetch_all($res,MYSQLI_ASSOC);
echo json_encode($row);
}
}else if($_SERVER['REQUEST_METHOD']=="PUT"){
$id=$_GET['id'];
$sql="UPDATE garbagedataset SET status=1 where id=$id";
$res=mysqli_query($conn,$sql);
if(!$res){
echo mysqli_error($conn);
}else{
echo 1;
}
}
?>