Database insertion & lt ;? Php $ connmysql_connect (& quot; localhost & quot;, & quot; root & quot;, & quot; 1234567 & quot;); mysql_query (& quot; SETNAMESutf8 & quot ;); if (! $ Conn) & nbsp ;{& nbsp; die (cocould database insertion
$ Conn = mysql_connect ("localhost", "root", "1234567 ");
Mysql_query ("set names 'utf8 '");
If (! $ Conn)
{
Die ('could not connect: '. mysql_error ());
}
Mysql_select_db ("code", $ conn );
$ SQL = "INSERT INTO keycode (key) VALUES ('$ _ POST [username]')";
If ($ _ POST [username]! = Null ){
Mysql_query ($ SQL, $ conn );
Echo "status = '$ _ POST [username]'";
} Else
Echo "no number! ";
Mysql_close ();
?>
Why can't I insert a parameter sent from the flex end ???
Echo "status = '$ _ POST [username]'" can be displayed. However, nothing is inserted in the database !!!!
Thank you !!!!!
------ Solution --------------------
It may be that the passed Chinese characters cannot be inserted normally. Try to use English. If possible, perform iconv transcoding in Chinese.
------ Solution --------------------
Mysql_query ($ SQL, $ conn) or die (mysql_error (); // check whether the error is correct.
Echo mysql_affected_rows ($ conn); // Check the number of entries in and out.
------ Solution --------------------
Is this not an error?
The key is a reserved mysql word, which must be escaped during other operations.
$ SQL = "INSERT INTO keycode ('key') VALUES ('$ _ POST [username]')";
------ Solution --------------------
I have made this mistake before.
------ Solution --------------------
Discussion
No !!! This is depressing.
I output the $ SQL statement like this: INSERT INTO keycode (key) VALUES ('17 ')
Then I run the prompt in mysql:
#1064-You have an error in your SQL syntax; check the manual that corresponds to your MySQL server vers ......