Php inserts garbled data into the database

Source: Internet
Author: User
PHPcode & lt; html & gt; & lt; head & gt; bookentryresult & lt;/head & gt; & lt; body & gt; & lt; h1 & gt; bookentryresult & php inserts garbled data into the database
PHP code
  Book entry resultBook entry result
  Query ($ query); if ($ result) {echo $ db-> affected_rows. "data is successfully input in this book. ";} Else {echo" data entry failed. ";}?>


I have used header () to convert the php page to UTF-8
Both the database and table are encoded in UTF-8.


------ Solution --------------------
Discussion
Mysql_query ('set names utf8'); it is not set to mysqli. it should be $ db-> query ('set names utf8 ');
Where did you see the inserted data garbled? Phpmyadmin?

------ Solution --------------------
I have encountered a normal program code, and the page shows normal, except for garbled characters in phpmyadmin. That's not the configuration of phpmyadmin, but I don't know how to change it. You can write a simple applet to read the database content to the page and view it.
------ Solution --------------------
Is there a problem with program code.
------ Solution --------------------
Execute mysql_connnet (…) first (......), After the database is linked, execute mysql_query ("set names UTF-8 ");

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.