PHP database insertion is garbled

Source: Internet
Author: User
PHP inserts a database with garbled characters. PHP obtains the html post content to the database. after the database is inserted, garbled characters are displayed. the database encoding has been set to UTF8. before the insertion, I ECHO it and it is not garbled, but it turns into garbled characters in the database. I don't know why. I have already searched for it, and I want to execute it first.

Mysql_query ("set names 'uft8'", $ link );

In this way, I will refresh the page after this execution. I don't know how to solve it. if one page is fixed, what should I do if multiple pages need to be inserted into data, thank you for your experience.


Reply to discussion (solution)

Have you set the php page encoding?

Header ('content-Type: text/html; charset = utf-8 ');

?>

Set. by default, this sentence is automatically loaded when a new PHP page is created.

By the way, mysql_query ("set names 'uft8'", $ link); here
Utf8 is best written as UTF8

Is the database determined to be UTF-8 encoded? Right-click the database property to see it!

See the encoding of your editor

Solved. thank you.

I also encountered garbled code. please solve it.
Mysql_select_db ("set names utf8 ");

Header ('content-Type: text/html; charset = utf-8 ');
Include "connect. php ";

Create table 'userinfo '(
'Id' varchar (32) not null comment 'primary key ID ',
'Truename' varchar (100) default null comment' name ',

Primary key ('id ')
) ENGINE = MyISAM default charset = utf8;

So the places are set to UTF-8, or garbled, novice just learn, please great God advice

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.