I need to parse the json string from an android application and insert it into mysql database using php
I tried to parse json from android using "$jsonData = file_get_contents('php://input');"
my code
include 'dbconnect.php';
if($_SERVER['HTTP_ORIGIN'] == "http://www.my-domain.com") {
header('Access-Control-Allow-Origin: http://www.my-domain.com');
header('Content-type: application/json');
header('Content-Type: application/x-www-form-urlencoded');
}
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");
$jsonData = file_get_contents('php://input');
$detail = json_decode($jsonData);
$cur_date = date('Y-m-d');
$title = $detail->title;
$description = $detail->description;
$deviceId = $detail->deviceid;
$companyId = $detail->companyId;
$sql = mysqli_query($db, "INSERT INTO notes (deviceId, companyId, title, description, createdDate) VALUES ('$deviceId', '$companyId', '$title', '$description', '$cur_date')");
if($sql)
{
echo json_encode("Success");
}
else
{
echo json_encode("Error!!");
}
Need to insert the values to database