Parsing json in php I get a json string from a page, convert it to a json Array, and insert it into the database, but all the inserted values are null, i'm sure I can get the json string. & Lt ;? Php & nbsp; include_once (incconn. php); & nbsp; $ json_string $ _ RE json parsing in PHP
I get a json string from a page, convert it to a json Array, and insert it into the database, but all the inserted values are null. I am sure I can get the json string.
Include_once ('Inc/conn. php ');
$ Json_string = $ _ REQUEST ["visitor"];
$ AddressInfo = json_decode ($ json_string, TRUE );
$ Name = $ addressInfo ['name'];
$ Idcard = $ addressInfo ['idcrd'];
$ Visitedphone = $ addressInfo ['visitedphone'];
$ Address = $ addressInfo ['address'];
$ Visitedorganization = $ addressInfo ['visitedorganization'];
Echo "1 $ visitedphone ";
Echo "2 $ address ";
Echo "3 $ visitedorganization ";
$ SQL = "insert into adress_list (name, idcrad, tel, adress, visitorganization) values ('$ name',' $ idcard ',' $ visitedphone ',' $ address ', '$ visitedorganization ');";
$ Rest = 0;
$ Rest = mysql_query ($ SQL );
Echo mysql_error ();
If ($ rest ){
Echo "Congratulations, upload successful! ";
} Else {
Echo "Upload failed. please upload again! ";
}
// Close the database
Mysql_close ($ con );
?>
This is my code...
------ Solution --------------------
$ Name = $ addressInfo ['Visitors '] [0] ['name.
------ Solution --------------------
A little less foreach, you will see it.
------ Solution --------------------
It should be written like this
$ AddressInfo = json_decode ($ json_string, TRUE );
$ AddressInfo = ['Visitors '] [0];
Here is your original code.