The php output is garbled, but the database is called, and it turns out to be garbled !!! The program is as follows & lt ;? Php $ q $ _ GET [& quot; q & quot;]; $ conmysql_connect (& quot; localhost & quot;, & quot; root & quot;, & quot; 198600 & quot;); if (! $ Con) & nbsp; {& nbsp; die (php output garbled problem
I only called the database, and garbled characters appeared !!!
The procedure is as follows:
$ Q = $ _ GET ["q"];
$ Con = mysql_connect ("localhost", "root", "198600 ");
If (! $ Con)
{
Die ('could not connect: '. mysql_error ());
}
Mysql_query ("set names 'gb2312 '");
Mysql_select_db ("my_db", $ con );
$ SQL = "SELECT * FROM persons WHERE nick = '$ Q '";
$ Query = mysql_query ($ SQL );
$ Rows = mysql_num_rows ($ query );
If ($ rows)
{
Echo 'user name registered ';
}
Else
{
Echo 'user name available ';
}
Mysql_close ($ con );
?>
The webpage code is gb2312.
The database code is utf8.
The problem is that I only called the database and did not write or output data from the database. why is the page output garbled !!
------ Solution --------------------
Add the header ('content-Type: text/html; charset = gb2312 ') to the header ');