I believe you have a general understanding of how to use PHP to query MySQL data. So next, we will start learning how to use PHP to add MySQL data. is it very exciting? First, create a query page:
The code is as follows:
Add record
You should remember that you have already introduced the technology of transferring values between PHP pages in previous topics. Similarly, on this page, when we click submit, we will pass the parameters ename and pcname to the add_finish.php page through the post method.
Next, let's take a look at how to use PHP to write a statement for adding MySQL data:
The 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 for PHP to add MySQL data. Then use mysql_query to execute this SQL statement.
Please note that you must pay attention to any symbol in the program, because this program passes the test normally. you only need to copy it all when copying it, however, you must pay attention to every detail when writing your own documents.
Another point is that you must make minor modifications to the program based on your database structure to meet your specific needs.
This topic briefly introduces how to use PHP to add MySQL data records. For a more detailed introduction, I will add additional instructions in future topics.