First set up the query page:
Copy CodeThe code is as follows:
Add a record
As you can remember, the technique of how to pass values between PHP pages has been described in the previous topic. Similarly, on this page, when we click Submit, we will pass the two parameters of ename and pcname to the add_finish.php page by means of post.
Next is the most important, let's take a look at how to write a statement to add MySQL data in PHP:
Copy CodeThe code is as follows:
$link =mysql_connect ("localhost", "root", "Administrator Password");
mysql_select_db ("Infosystem", $link);
$exec = "INSERT into info (ename,pcname) VALUES ('". $_post["ename"]. "', '". $_post["Pcname"]. "')";
mysql_query ("SET NAMES GB2312");
mysql_query ($exec, $link);
Mysql_close ($link);
echo "added successfully! ";
?>
The red part is the key SQL statement that PHP adds MySQL data to. Then use mysql_query to execute the SQL statement.
To remind you, be sure to pay attention to any one of the symbols in the program, because this program is passed through my test normal, everyone in the copy as long as all copies can be, but in your own writing must pay attention to every detail.
Another point is that we have to adapt to their own database structure of the program to make minor changes to meet the specific needs of everyone.
Today's topic is relatively brief, and outlines how to add MySQL data records in PHP. In a more detailed introduction I will add a note on future topics.
http://www.bkjia.com/PHPjc/319146.html www.bkjia.com true http://www.bkjia.com/PHPjc/319146.html techarticle First build the query page: Copy the code as follows: HTML Head/head body h3 add record/h3 formaction= "add_finish.php" method= "POST" Employee Name: inputtype= "Text" Size=25name= "En ...