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