PHP json JavaScript
Connect Database Code
$conn =mysql_connect ("127.0.0.1", "root", "root") or Die ("Connection database failed!");
mysql_select_db ("Resume2", $conn) or Die ("No database!");
mysql_query ("SET NAMES UTF8");
Save an array to the database
$value =array ("name" =>$_post[' job_name ');
$var =json_encode ($value);
mysql_query ("INSERT into ' Resume ' (' job_id ', ' job_pass_status ', Job_content ') VALUES (null,1, ' $var ')", $conn);
And then read the data that you just deposited from the database
$query =mysql_query ("select * from ' Resume ' WHERE ' job_id ' = 10"); The ID you just deposited is 10.
$row =mysql_fetch_array ($query);
$num =json_decode ($row [' job_content '],true);
echo $num [' name '];
Question, when I job_name for "Zhang Small white", output $num[' name '] is "u6234u660eu534e", ask the big God to see where the problem is. Why is the output not the name "Zhang Xiao Bai"? "
Reply to discussion (solution)
JSON only accepts UTF-8 encoded characters, confirming that your page is UTF-8 encoded.
JSON only accepts UTF-8 encoded characters, confirming that your page is UTF-8 encoded.
When I created the project and HTML file is unified with Utf-8, with Json_encode transcoding to save to the database, such as I write "white", but in the database is
"u6234u660eu534e" in this form. Read the database can only read "u6234u660eu534e" This, do not know how to turn it into a "small white" this Chinese code.
echo $_post[' job_name ']; Is it normal?
echo $_post[' job_name ']; Is it normal?
Normal.
Why is "Zhang Xiao Bai"?
$s = ' "\u6234\u660e\u534e";
echo Json_decode ($s); Daiminghua
Echo Json_encode (' Zhang Xiao Bai '); "\u5f20\u5c0f\u767d"
You don't have an accurate description of your problem.
Problem, has been resolved. It's the MySQL transfer problem.