Questions about simple message board for new php beginners

Source: Internet
Author: User
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.

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.