The query string found in the database is garbled on the webpage.

Source: Internet
Author: User
The query string from the database is garbled on the webpage. the MYSQL database uses echo to output the data to the webpage, what's strange is that only one part is garbled, but the rest is normal. $ SQL = & quot; selectusernamefrompw_memberswher: garbled characters are displayed on the web page.
The MYSQL database uses echo to output the data from it to the webpage. it is strange that only one part of the database is garbled, but other parts are normally displayed.

$ SQL = "select username from pw_members where uid =? ";
$ Result = $ handler-> exeSql ($ SQL, array ($ winduid), "select ");
If ($ result ){
Echo ''. $ result [" username "].''} else {
Echo 'unknown username ';
}

This is the code, and the web page starts

The database information is:
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
Field Information:
Field: username
Type: varchar (18)

Not all texts are garbled. only this part is garbled. please explain it ~~

------ Solution --------------------
Unknown user name. I believe you can see this is not garbled.
Your database uses UTF-8 for storage, but the HTML displayed on the front end uses GBK encoding. Naturally, some of them are always garbled.
You can transcode $ result ["username"] to GBK.
$ Result ["username"] = iconv ('utf-8', 'gbk', $ result ["username"]);
Save your. php or. html file as UTF-8
------ Solution --------------------
Database encoding is UTF-8 you will be the page encoding file encoding are set to UTF-8 on the worry-free, why have to turn around?
Specify the data encoding before getting the database data.

Set names ('utf8'); // gbk

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.