i have url this:
http://localhost/datas.php?[{ id :27,latt:8.55699,ltd:76.882,tm:11:46:51}, { id :97,latt:8.55699,ltd:76.882,tm:11:46:52}, { id :31,latt:8.55699,ltd:76.882,tm:11:46:52}, { id :96,latt:8.55703,ltd:76.8815,tm:11:53:22}]
i need enter these values database using php
i tried many ways.but no way, not working.
so far done this.
$response = array(); $response["data"] = $array; $json = json_encode($response); var_dump($json);
but shows data null.
please me solve this
never ever pass json through url, can convert string , decode below :
test.php
<?php $json = '[{ "id": 27, "latt": 8.55699, "ltd": 76.882, "tm": "11: 46: 51" }, { "id": 97, "latt": 8.55699, "ltd": 76.882, "tm": "11: 46: 52" }, { "id": 31, "latt": 8.55699, "ltd": 76.882, "tm": "11: 46: 52" }, { "id": 96, "latt": 8.55703, "ltd": 76.8815, "tm": "11: 53: 22" }]'; echo 'http://localhost/test.php?data='.base64_encode($json); ?>
test1.php
<?php $getdata = $_get['data']; $cjson = json_decode(base64_decode($getdata)); print_r($cjson); ?>
result :
array ( [0] => stdclass object ( [id] => 27 [latt] => 8.55699 [ltd] => 76.882 [tm] => 11: 46: 51 ) [1] => stdclass object ( [id] => 97 [latt] => 8.55699 [ltd] => 76.882 [tm] => 11: 46: 52 ) [2] => stdclass object ( [id] => 31 [latt] => 8.55699 [ltd] => 76.882 [tm] => 11: 46: 52 ) [3] => stdclass object ( [id] => 96 [latt] => 8.55703 [ltd] => 76.8815 [tm] => 11: 53: 22 ) )
also json not in correct format. please use validated json.
Comments
Post a Comment