Php output garbled-php Tutorial

Source: Internet
Author: User
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 ');

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.