PHP form data is written to MySQL code, and php form is written to mysql. PHP form data writes MySQL code, php form writes mysqlh1 insert operation h1? Phpif (! Isset ($ _ POST [submit]) {if no form is submitted, is a form displayed? Formaction PHP form data write MySQL code, php form write mysql
INSERT operation
Reference: http://www.cnblogs.com/roucheng/p/phpmysql.html
The above code uses different formats. I don't know which format is better.
- INSERT operation
- If (! Isset ($ _ POST ['submit ']) {
- // If no form is submitted, a form is displayed.
- ?>
- }
- Else
- {
- // If the form is submitted
- // Database connection parameters
- $ Host = "localhost ";
- $ User = "root ";
- $ Pass = "zq19890319 ";
- $ Db = "phpdev ";
- // Obtain the value in the form, check whether the value in the form complies with the standard, and escape it to prevent SQL injection.
- $ Country = empty ($ _ POST ['country'])? Die ("enter the country name "):
- Mysql_escape_string ($ _ POST ['country']);
- $ Animal = empty ($ _ POST ['Animal '])? Die ("Enter English name "):
- Mysql_escape_string ($ _ POST ['Animal ']);
- $ Cname = empty ($ _ POST ['cname'])? Die ("Enter Chinese name "):
- Mysql_escape_string ($ _ POST ['cname']);
- // Open the database connection hovertree.com
- $ Connection = mysql_connect ($ host, $ user, $ pass) or die ("Unable to connect! ");
- // Select a database
- Mysql_select_db ($ db) or die ("Unable to select database! ");
- // Construct an SQL query
- $ Query = "insert into symbols (country, animal, cname) VALUE ('$ country', '$ animal', '$ cname ')";
- // Execute this query
- $ Result = mysql_query ($ query) or die ("Error in query: $ query.". mysql_error ());
- // The insert record number is displayed after the insert operation is successful.
- Echo "the record has been inserted, mysql_insert_id () =". mysql_insert_id ();
- // Close the current database connection
- Mysql_close ($ connection );
- }
- ?>
When h1 insert operation/h1? Php if (! Isset ($ _ POST ['submit ']) {// if no form is submitted, is a form displayed? Form action = "...