PHP add MySQL Data logging code _php Tutorial

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

  • Related Article

    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.