Parsing json in PHP
I get a JSON string from a page and then convert it to a JSON array and then insert it into the database, but all that is inserted is NULL, and I'm sure I can get to 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 success!";
}else{
echo "Upload failed, please re-upload!";
}
Close the database
Mysql_close ($con);
?>
This is my code to seek the Great God Guide, urgent beg ...
------Solution--------------------
$name = $addressInfo [' Visitors '][0][' name ']; That's fine.
------Solution--------------------
One less layer of foreach, and you'll see.
------Solution--------------------
It should be written.
$addressInfo =json_decode ($json _string,true);
$addressInfo =[' visitors '][0];
It's your original code.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.