Mysql Chinese cannot be read... This is the encoding method of the mysql database. this is the result of background data. if you do not use Chinese, the data is normally written to the background. if you use Chinese, the data cannot be written. (Pay attention to the last few rows of data) if you write Chinese characters directly to the database, it will be displayed. PHP code & lt ;? Phpif (isset ($ _ POST ['b1 ']) mysql cannot read Chinese characters...
This is the encoding method of the mysql database.
This is the result of background data. if you do not use Chinese, the data is normally written to the background. if you use Chinese, the data cannot be written. (Check the last few rows of data)
If you write Chinese characters directly to the database, it will be displayed.
PHP code
If (isset ($ _ POST ['b1 '])
{
$ Username = $ _ POST ["username"];
$ Message = $ _ POST ["message"];
If ($ username = "")
{
Echo" Alert ('Enter your name! '); Script ";
If ($ message = "")
{
Echo" Alert ('Enter the message content! '); Script ";
}
}
Else
{
$ Addtime = date ("y-m-d h: m: s ");
$ Id = mysql_connect ("localhost", "root", "1234 ");
Mysql_select_db ("gbook", $ id );
$ Query = "insert into message (author, addtime, content, reply) values ('$ username',' $ addtime', '$ message ','')";
$ Result = mysql_query ($ query, $ id );
Mysql_close ($ id );
// Echo "result =". $ result;
Echo" Alert ('message successful, click OK to view the message! '); Location. href = 'index. php'; script ";
}
}
------ Solution --------------------
$username=iconv('gb2312','utf-8',$_POST["username"]);
$message=iconv('gb2312','utf-8',$_POST["message"]);
------ Solution --------------------
The database code is utf8.
If you write Chinese characters directly to the database, it will be displayed. (The last line)
Phpmyadmin will perform encoding settings, so there is no problem naturally.
Your code is not encoded, so it is normal to have a problem!
When the file encoding is gbk (ANSI in windows), it should
Mysql_query ('set names gbk ');
When the file encoding is UTF-8, it should be
Mysql_query ('set names utf8 ');