Php production registration page Chinese cannot be saved into 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:
========================================================== ========================================================== ======
$ 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 ..?


Reply to discussion (solution)

Can I paste the database table structure to see if it is a problem with the database field type?

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.

Can I paste the database table structure to see if it is a problem with the database field type?

This is my database table structure

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.

This is the file encoding method of my phpdesigner. The database uses utf8.

If it cannot be inserted, an error is reported!
Echo mysql_error ();
You can understand the crux of the problem.



If it cannot be inserted, an error is reported!
Echo mysql_error ();
You can understand the crux of the problem.

Set according to the moderator, but still cannot be added. no error is displayed. check the database table and find it saved. a space is saved.
.

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.
Correct modification in this way !.. But the output to the page becomes garbled again... I don't know what the problem is ..


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.
Correct modification in this way !.. But the output to the page becomes garbled again... I don't know what the problem is ..
That's because the character encoding on your page is inconsistent with that on the database. it will be consistent with that on both sides in the future design. now, use iconv to convert it back.



Send an Ecshop to show you.

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


If it cannot be inserted, an error is reported!
Echo mysql_error ();
You can understand the crux of the problem.

Set according to the moderator, but still cannot be added. no error is displayed. check the database table and find it saved. a space is saved.
Did I tell you how to set it?
I will only tell you how to find the reason
You didn't post the error message. how can I tell you how to do it?



If it cannot be inserted, an error is reported!
Echo mysql_error ();
You can understand the crux of the problem.

Set according to the moderator, but still cannot be added. no error is displayed. check the database table and find it saved. a space is saved.
Did I tell you how to set it?
I will only tell you how to find the reason
You didn't post the error message. how can I tell you how to do it?
Amount .. I mean, I added the code that prompts the error content, and there was no error prompt... then I checked the database and found that the database was actually saved, but the space was saved...

User_id should be set to auto-increment attribute

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.