Let's help my younger brother. I think there is something wrong with this php mysql writing.

Source: Internet
Author: User
Let's take a look at this php mysql writing problem? Html: & lt; center & gt; & nbsp; & lt; form & nbsp; action = "addData. php "& nbsp; method =" post "& nbsp; target =" _ blank. can you help me to see if there is a problem writing mysql in php?
Html:
 
   
  


Php:
 ///// // Create a connection with mysql
$ Host = "localhost"; $ user = "root"; $ pwd = ""; $ DataBaseName = "db_appdata"; $ db_name = "appdata ";
$ Con = mysql_connect ($ host, $ user, $ pwd );
If (! $ Con)
{
Die ('database connection failed: '. mysql_error ());
}
Mysql_select_db ($ DataBaseName, $ con); // select a database
//// // Insert data into the table
Mysql_query ("insert into $ db_name (Name, pwd)
VALUES (. trim ($ _ POST ["u_user"]),. trim ($ _ POST ["u_pwd"]) ");
Echo "added successfully ";
// Close the connection
Mysql_close ($ con);?>


The database can be connected successfully. Why can't I write data?
------ Solution --------------------
An error occurred while inserting SQL statements.
And $ _ POST ["u_User"]

------ Solution --------------------
Mysql_query ("insert into $ db_name (Name, pwd)
VALUES ('". trim ($ _ POST [" u_user "])."', '". trim ($ _ POST [" u_pwd "])."' ");
------ Solution --------------------
This POST was last edited by xuzuning at 12:39:58 on. 1. name = "u_User" is in the form, and $ _ POST ['U _ user'] is required after submission.
Php variables are case sensitive.
2. when $ _ POST ["u_User"] is written to the string, $ _ POST ["u_User"] should be included in {}: {$ _ POST ["u_User"]}
Or write $ _ POST [u_User]
This is a php writing rule and must comply

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.