PHP simple code for submitting data to MySql and adding records _ PHP Tutorial

Source: Internet
Author: User
Simple code for PHP to submit data to MySql to add records. Today, a webmaster asked me a very simple question: how can I use PHP to add records to Mysql? Now let's give a simple code for storing data and analyze it with a few words. Today, a webmaster is asking a very simple question-how to use PHP to add records to Mysql? Now, let's give a simple code for data storage. after a few analysis sentences, the experts will not read it. this is a very basic example.

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

Copy to ClipboardReference: [www.bkjia.com] Mysql_connect ("localhost", "root", ""); // Connect to MySQL
Mysql_select_db ("hello"); // select a database
?>

Of course, the premise is that you have installed the WEB server, PHP, and MySQL, and created the MySQL table "cnbruce"

The three parameters of mysql_connect () are MySQL address, MySQL User name, and MySQL password.

Then, the data is transmitted through the WEB page, so that PHP writes data to the table specified by the MySQL database through SQL statements, such as creating the file liehuo_net.php

Copy to ClipboardReference: [www.bkjia.com] Require_once ("conn. php"); // reference the database link file
$ Uname = $ _ GET ['n']; // The GET method is passed as a URL parameter.
$ Psw = $ _ GET ['P'];
$ Psw = md5 ($ psw); // Use MD5 encryption directly

$ SQL = "insert into members (username, password) values ('$ uname',' $ psw ')";
Mysql_query ($ SQL); // use SQL statements to insert data

Mysql_close (); // Close the MySQL connection
Echo "successfully entered data ";
?>

Why? Now let's give out a simple code for storing data, and analyze it with a few words...

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.