MySQL Console inserted Chinese characters are not garbled, PHP insertion is garbled;

Source: Internet
Author: User
Tags sql error phpmyadmin
Header ("Content-type:text/html;charset=utf-8");
$title =$_post[' F_title '];
$content =$_post[' f_content '];
Connecting to a database
$link =mysql_connect (' localhost ', ' root ', ');
Select Database
mysql_select_db (' BBS ', $link);
Set character sets
mysql_query ("Set names UTF8");
Generating SQL statements
$sql = "INSERT into Bss_info (title,content,add_time) VALUES (' $title ', ' $content ', Now ())";
Execute SQL statement
$rs =mysql_query ($sql);
Generate SQL Error prompt
Echo Mysql_error ();
Page Information Tips
if ($RS)
{
echo "message added successfully!";
}else
{
echo "message added failed!";
}
?>


Reply to discussion (solution)

1, the table is UTF8 code?
2, file encoding is Utf-8 code?

When you insert data that is UTF-8 encoded
Only need mysql_query ("Set names UTF8")

1, the table is UTF8 code?
2, file encoding is Utf-8 code?



Open my above PHP page through Notepad, file?? Save as display encoding when Utf-8
Mmsql:my.ini file shows: Default-character-set=utf8
I really don't know what's wrong!

My qq:380492399, which master knows the problem, can help me to see remotely, grateful.

In
Execute SQL statement
Before joining
echo Base64_encode ($sql);
Post the results

Your database is not necessarily utf8 ... If you don't, you'll get a problem.
Take a look at it with phpMyAdmin ...

Your database is not necessarily utf8 ... If you don't, you'll get a problem.
Take a look at it with phpMyAdmin ...




Is the character set setting of the database not the "Default-character-set=utf8" in the My.ini file, is there any other place to set it up?

Reference to the 6 floor phpnewnew reply: Your database is not necessarily utf8 ... If you don't, you'll get a problem.
Take a look at it with phpMyAdmin ...


Is the character set setting of the database not the "Default-character-set=utf8" in the My.ini file, is there any other place to set it up?



You see... He called the default ... Which means you can also customize the table ...
Right?

Let's go to phpmyadmin. What kind of code is the database setup?

Thank you for your warm reply, the console character set should be 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.