PHP form data is written into the MySQL database code, and php form mysql database. The PHP form data is written into the MySQL database code. The php form mysql database does not talk much about it. you can directly post code to everyone. the specific code is as follows: h insert operation hphpif (! Isset (PHP form data written to the MySQL database code, php form mysql database
If you don't talk much about it, paste the code directly. the specific code is as follows:
<? Php} else {// if the form is submitted // database connection parameter $ host = "localhost"; $ user = "root"; $ pass = "zq "; $ db = "phpdev"; // why do I ask hovertree.com//obtain the value in the table list, check the value in the table list to conform to the standard, and make it right to prevent sqlinjection $ country = empty ($ _ POST ['country'])? Die ("enter country name"): mysql_escape_string ($ _ POST ['country']); $ animal = empty ($ _ POST ['Animal '])? Die ("Enter the English name"): mysql_escape_string ($ _ POST ['Animal ']); $ cname = empty ($ _ POST ['cname'])? Die ("Enter Chinese name"): mysql_escape_string ($ _ POST ['cname']); // open the database connection $ connection = mysql_connect ($ host, $ user, $ pass) or die ("Unable to connect! "); // Select the 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 (); // after the insert operation is successful, the record number echo "the record has been inserted, mysql_insert_id () = ". mysql_insert_id (); // close the current database connection mysql_close ($ connection) ;}?>
The above code uses different formats. I don't know which format is better.
<? Php} else {// if the form is submitted // database connection parameter $ host = "localhost"; $ user = "root"; $ pass = "zq "; $ db = "phpdev"; // obtain the value in the form, check whether the value in the form complies with the standard, and perform proper escape, prevent SQL injection $ country = empty ($ _ POST ['country'])? Die ("enter country name"): mysql_escape_string ($ _ POST ['country']); $ animal = empty ($ _ POST ['Animal '])? Die ("Enter the English name"): mysql_escape_string ($ _ POST ['Animal ']); $ cname = empty ($ _ POST ['cname'])? Die ("Enter Chinese name"): mysql_escape_string ($ _ POST ['cname']); // why does it ask $ connection = mysql_connect ($ host, $ user, $ pass) or die ("Unable to connect! "); // Select the 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 (); // after the insert operation is successful, the record number echo "the record has been inserted, mysql_insert_id () = ". mysql_insert_id (); // close the current database connection mysql_close ($ connection) ;}?>
The above is the code for writing PHP form data into the MySQL database. I hope it will help you!
I don't need to talk about it anymore. I just paste the code directly. the specific code is as follows: h insert operation/h php if (! Isset (...