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.