Home >Backend Development >PHP Tutorial >Simple code for PHP to submit data and add records to MySql_PHP Tutorial

Simple code for PHP to submit data and add records to MySql_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 14:53:441215browse

Today a webmaster asked Liehuo a very simple question - how to use PHP to add records to Mysql? Now I will give you a simple code to store data, with a few words of analysis, experts will not Look, very basic example.

There are three steps for PHP to write data to the MySQL database:

1. Establish a connection between PHP and MySQL

2. Open the MySQL database

3. Accept the page Data, PHP is entered into the specified table

Steps 1 and 2 can directly use a database link file: conn.php

Copy to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com] mysql_connect("localhost","root","");//Connect to MySQL
mysql_select_db("hello");//Select database
?>

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

The three parameters in mysql_connect() are MySQL address, MySQL username and MySQL password

Then the data is transferred through the WEB page, and PHP writes the data into the table specified in the MySQL database through SQL statements, such as creating a new file liehuo_net.php

Copy to ClipboardLiehuo.Net CodesQuoted content: [www.bkjia.com] require_once("conn.php");//Reference database link file
$uname = $_GET['n'];//GET method passes URL parameters
$psw = $_GET['p'];
$psw=md5($psw);//Use MD5 encryption directly

$sql = "insert into members(username,password) values ​​('$uname' ,'$psw')";
mysql_query($sql);//Insert data using SQL statements

mysql_close();//Close the MySQL connection
echo "Successfully entered data";
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364717.htmlTechArticleToday a webmaster asked Agni about a very simple question: How to use PHP to add records to Mysql? Just get one now A simple code for storing data is given, and with a few words of analysis, an expert can...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn