Php creates a registration page. Chinese characters cannot be saved to SQL for solving.

Source: Internet
Author: User
The Chinese character of the php registration page cannot be saved to the SQL solution. a registration page is created in html and submitted to the php page. data is transmitted using the post method. However, if the Chinese character is entered in the text box, it cannot be saved to the SQL database. The following is the key code for solving the problem: the Chinese character on the php production registration page cannot be saved to SQL for solving.
Create a registration page with html, submit it to the php page, and send data using the post method. However, if the text box contains Chinese characters, it cannot be saved to the SQL database. The following is the key code:
========================================================== ========================================================== ======
$ Userid = $ _ POST ['userid'];
$ Username = $ _ POST ['username'];
$ Userpwd = $ _ POST ['userpwd'];
$ Userage = $ _ POST ['userage'];
$ Usersex = $ _ POST ['usersex '];
$ Conn = mysql_connect ("localhost", "root ","");

Mysql_select_db ("newdb", $ conn );

$ SQL = "INSERT INTO usersinfo (userid, userpwd, username, userage, usersex) values ('$ userid',' $ userpwd ',' $ username ',' $ userage ', '$ usersex ')";
Mysql_query ("set names 'utf8 '");
$ Query = mysql_query ($ SQL, $ conn );
========================================================== ========================================================== ======
Userid usepwd userage is a number that can be stored in the SQL database, but username usersex cannot be stored,
Open phpmyadmin to view the database, and find that there is only one space in the columns in Chinese, saving failed.
I don't know what's going on. I added:
Echo $ userid ."
";
Echo $ username ."
";
Echo $ userpwd ."
";
Echo $ userage ."
";
Echo $ usersex ."
";
If any variables can be output normally, it indicates that the value is not a problem, but a problem occurs when the data is stored in the database. do you want to encode the data ..?

Php database


------ Solution --------------------
Can I paste the database table structure to see if it is a problem with the database field type?
------ Solution --------------------
Generally, it is a character encoding problem. maybe your page is UTF8 for the GB2312 Database. you can use iconv ("gbk", "UTF-8", $ _ POST ['XX']) to convert it down.
------ Solution --------------------


Send an Ecshop to show you.

In addition, the webpage code encoding must be consistent with that of the database.

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.