Sample code for saving data from a Mysql database using php

Source: Internet
Author: User
In php, the insert and update methods are the two most commonly used data storage methods for mysql databases. next I will introduce the mysql data storage methods for beginners. PHP writes data to the MySQL database in three steps: 1. PHP and MyS... in php, the insert and update methods are the two most commonly used data storage methods for mysql databases. next I will introduce the mysql data storage methods for beginners.

PHP writes data to the MySQL database in three steps:

1. establish a connection between PHP and MySQL

2. open the MySQL database

3. accept page data. input PHP Data to the specified table.

Steps 1 and 2 can directly use a database link File: conn. php. the code is as follows:

 

Of course, the premise is that the WEB server, PHP, and MySQL have been installed, and the MySQL table "mythroad" and mysql_connect () are set to the MySQL address, MySQL User name, and MySQL password respectively, then, data is transmitted through the WEB page, so that PHP can write data to the table specified by the MySQL database through SQL statements, such as creating a file post. php code:

 

Test Page: http: // 127.0.0.1/post. php? N = mythroad & p = mythroad, you can insert the new data "mythroad" to the username field and "mythroad" to the password field to the members Table of MySQL database hello.

If form post is used, we can use post for acceptance. The following describes how to update data. The example code is as follows:

 

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.