<?php
// array for JSON response
$response = array();
$response["list"] = array();

require_once __DIR__ . '/db_config.php';

if (isset($_POST['JSON'])) {

    $con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());

    $JSON_Received = $_POST['JSON'];
    $obj = json_decode($JSON_Received, true);                      

    foreach($obj as $key => $value )  {  

        $companyname = $value['COMPANYNAME'];
        $emailid= $value['EMAILID'];
        $location= $value['LOCATION'];
        $checkinname= $value['CHECKINNAME'];
        $latitude= $value['LATITUDE'];
        $longitude= $value['LONGITUDE'];
        $date= $value['DATE'];
        $time= $value['TIME'];
        $id=$value['_id'];
        
        $query="INSERT INTO location(companyname, emailid, location, checkinname, latitude, longitude, date, time) VALUES ('$companyname', '$emailid', '$location', '$checkinname', '$latitude', '$longitude', '$date', '$time') ";
        $result = mysqli_query($con,$query);

    if ($result) {
        array_push($response["list"],$id);
    }
}
    mysqli_close($con);

}
echo json_encode($response);
?>