I have a PHP
script that receives a JSON string from an Android app through the hashmap.
This is the json string called obj
:
{
"total": "25",
"buyer_id": "1",
"order": [
{ "id": "1", "name": "cosmo" },
{ "id": "5", "name": "Choco" },
{ "id": "22", "name": "gogo" }
]
}
this is the script
$json = $_POST['obj'];
$data = json_decode($json,true);
//initialize the variables to the json object param
$buyer_id = $data->buyer_id;
$total = $data->total;
//insert the order in the orders table
$sql_orders = "insert into orders(buyer_id,total) values
('$buyer_id','$total')";
$res = mysqli_query($con,$sql_orders);
it seems to me that the json_decode isn't working because the variables are null; when i echo
any of of the variables :
echo $data.total;
the output is NULL.