Home >Backend Development >PHP Problem >What to do if php insert into fails
Solution to failed php insert into: 1. Check the encoding format; 2. Change "mysql_set_charset('utf8');" to "mysql_set_charset('utf-8');"; 3. Open mysql Find the corresponding table and modify its encoding format to "utf8".
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
What should I do if php insert into fails?
Solution|php insert into insertion failed|Incorrect string value: '\xE5\x88\x98\xE5\xAE\x89' for column 'name
//代码插入数据 $myID = Null; $myName='刘安'; $myMoney=100; $sqlstatement="insert into users values(Null, '{$myName}', '{$myMoney}')"; $result=mysql_query($sqlstatement); var_dump($result);
always false false false I wanted to die, I wanted to die.
I didn’t check the documentation later and suspected it was a problem with the encoding format
Changed
mysql_set_charset('utf8');
to
mysql_set_charset('utf-8');
Are you angry that this problem has been solved...
I learned PHP by watching videos on the Chinese website, but he used utf8 and it worked, but mine couldn't. . . I don’t know the reason, but I’ll record it to prevent it from happening again
Continued -----------
Change it back again
mysql_set_charset('utf8');
I thought it was solved Not
I’m even more angry. It seems to be solved below, but when I use the cmd command to query garbled characters, I feel reluctant to think that it is a problem with the cmd encoding format.
When using Navicat Premium again, the code is garbled.
The final solution is also posted.
It is because the encoding format of the database table is incorrect. Open mysql to find the corresponding table and modify its encoding. After the format is "utf8", the problem will be solved!
Of course it is difficult to find the modification table in Navicat Premium and cannot even find it, so the effect of changing the encoding where the field is modified is the same
Your problem has been solved. Next is the summary. Don’t read it
$sqlstatement="insert into users values(Null, '{$myName}', '{$myMoney}')"; $result=mysql_query($sqlstatement); var_dump($result); echo mysql_error();
1 You can use this mysql_error() to find specific bugs and solve them
2 Find specific problems through specific bugs, don’t go further and further by describing them blindly, such as php insert into in the title Insertion failed....
Recommended study: "
PHP Video TutorialThe above is the detailed content of What to do if php insert into fails. For more information, please follow other related articles on the PHP Chinese website!