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 and PHP enters it into the specified table
Steps 1 and 2 can be used directly A database link file is enough: conn.php
Copy the code The code is as follows:
mysql_connect("localhost","root","");//Connect to MySQL
mysql_select_db( "hello");//Select the database
?>
Copy the code The code is as follows:
< ;?php
require_once("conn.php");//Reference the database link file
$uname = $_GET['n'];//The 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";
?>