PHP inserting data into the database garbled related issues

Source: Internet
Author: User
PHP inserting data to database garbled problem
PHP code
!--code highlighting produced by Actipro Codehighlig Hter (freeware) http://www. Codehighlighter.com/-->book Entry result book

entry result

!--? phpheader ("content-type:text/html;charset= Utf-8 "); $isbn =$_post[' ISBN ']; $author =$_post[' author '); $title =$_post[' title ']; $price =$_post[' price '];if (! ( $ISBN | | $author | | $title | | $price) {echo "Please confirm that each line has input data"; Exit;} if (!GET_MAGIC_QUOTES_GPC ()) {$ISBN =addslashes ($ISBN); $author =addslashes ($author); $title =addslashes ($title); $price =addslashes ($price);} mysql_query (' Set names UTF8 '); @ $db =new mysqli (' localhost ', ' root ', ' root ', ' books '); if (Mysqli_connect_error ()) {echo " Link database not successful "; Exit;} Header ("Content-type:text/html;charset=utf-8"); $query = "INSERT Into Books (ISBN, author, title, price) VALUES ('". $ISBN . "', '". $author. "', '". $title. "', '". $price. "')"; $result = $db--->query ($query), if ($result) {echo $db->affected_rows. "The book data entry was successful. ";} Else{echo "Data entry failed. ";}?


I have used the header () to turn the PHP page into Utf-8
Both the database and the table are encoded UTF-8


------Solution--------------------
discuss
mysql_query (' Set names UTF8 '); And Mysqli does not match the tune, should be $db->query (' Set names UTF8 ');
Where did you see the inserted data garbled? phpMyAdmin?

------Solution--------------------
I have encountered the program encoding is normal, the page display is normal, but phpmyadmin in the case of garbled. That's phpMyAdmin's configuration, but I don't know how to fix it. You can write a simple applet to read the database contents to the page display to see
------Solution--------------------
The program code is not a problem.
------Solution--------------------
The Mysql_connnet (...) should be executed first, and the database is linked to mysql_query ("Set names Utf-8").
  • Related Article

    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.