Method to solve the disorder of Chinese content in MySQL database submitted by PHP

Whether it is ASP or PHP programming language, or even other web languages, the basic application is nothing more than the requirements of database adding, reading, editing, deleting, and so on. No matter how complex the functional projects are, they are all carried out around these. In the input MySQL database when the Chinese data submitted garbled problem, this problem for beginners learning PHP must have encountered.

In fact, the problem is relatively simple, it must be caused by the wrong coding. For example, page coding, database field coding, and database link coding. Here, we all adopts UTF-8 coding. We need to find these problems and solve the problem of garbled code.

First, page coding

We need to keep UTF-8 coding in web pages.

Second, the coding problem when creating the database

In the article “common commands and data type settings for creating MySQL database and data table with PHP”, we uses the method of SQL direct import. When we add database fields, if we need to keep all UTF-8 codes, we need to keep utf8 of database fields in the last “charset = utf8”.

Third, the coding of database links

In the database link file, we need to set:

mysql_ query(“set names ‘utf8′”);

The same is the utf8 encoding setting.

In this way, through the unified coding of three places, we can definitely solve the problem of garbled code after submitting data.

Related Article
Two methods of using CSS style to intercept the length of the title do not need to use functions

For example, when we make the website template, or choose to download to a good default, maybe due to the Read more

Two regular expression verification methods for PHP user registered mailbox

Generally, when we register or log in to an account on the web, we need to verify not only whether Read more

Three common methods of PHP connecting MySQL database

For PHP entry-level users, we only need to master the basic database write, read, edit, delete and other basic operations. Read more

Solve the problem of Chinese garbled in VIM edit file under Linux system

If we need to edit the files in the Linux system, we may download them locally, open them with an Read more

Leave a Reply

Your email address will not be published. Required fields are marked *

To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image