Add MySQL data record Code in PHP

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.