Php beginners seek help from simple message boards. this is the source code & lt ;? Php $ conmysql_connect (& quot; localhost & quot;, & quot; root & quot;, & quot;); if (! $ Con) & nbsp ;{& nbsp; die (Couldnotconnect:. mysql_error (); & nbsp php beginner help Simple Message Board questions
This is the source code
$ Con = mysql_connect ("localhost", "root ","");
If (! $ Con)
{
Die ('could not connect: '. mysql_error ());
}
$ Db_selected = mysql_select_db ("test_db", $ con );
If (! $ Db_selected)
{
Die ("Can \'t use test_db:". mysql_error ());
}
$ SQL = "INSERT INTO 'test _ db '. 'form' ('name', 'pass') VALUES (\ 'fdgsdfg \ ', \ 'dsfgsdfg \');";
Mysql_query ($ SQL, $ con );
?>
It seems that the database can be connected, but it cannot be updated to the database.
The database is very simple. The field type sorting attribute is empty. Additional operations are performed by default.
The field has two names and pass
Hope you can come and see
------ Solution --------------------
"Insert into 'test _ db'. 'form' ('name', 'pass') VALUES (\ 'fdgsdfg \ ', \ 'dsfgsdfg \');"
First, because this string is enclosed in double quotation marks, it does not conflict with single quotation marks, so \ escape is not allowed.
You do not need to end with a semicolon. Because mysql_query () itself only sends one query statement to mysql at a time.
Modified code:
PHP code
$ SQL = "INSERT INTO 'test _ db '. 'form' ('name', 'pass') VALUES ('fdgsdfg', 'dsfg') "; mysql_query ($ SQL, $ con) or exit (mysql_error ()); // This is the focus and it will tell you why the error occurred.