Principle Steps
1,php use mysql_connect to connect with MySQL database
2, open MySQL database
3, accept the page data, PHP input to the specified table
4, and then use Mysql_query to execute and save the SQL to the database.
Connection MySQL database super simple as follows
| The code is as follows |
Copy Code |
<?php mysql_connect ("localhost", "root", "");//Connect MySQL mysql_select_db ("Hello");//Select Database ?>
|
Example 1
| The code is as follows |
Copy Code |
<?php Require_once ("conn.php");//referencing Database link file $uname = $_get[' n '];//get method is passed to the URL parameter $PSW = $_get[' P ']; $PSW =md5 ($PSW);//Direct use of MD5 encryption $sql = "INSERT into the members (Username,password) VALUES (' $uname ', ' $psw ')"; mysql_query ($sql);//Borrow SQL statement to insert data Mysql_close ()//close MySQL connection echo "Successful data entry"; ?> |
It's a much simpler combination.
| code is as follows |
copy code |
| . $ uname = $_get[' n '];//get method passes $PSW =md5 ($_get[' P ']) for the URL parameter;//Direct use MD5 encryption $conn =mysql_connect ("localhost", "root" , "");//connect mysql $sql = INSERT INTO members set Username= ' uname ', password= ' $PSW '; mysql_db_query ("Hello", $sql, $conn);//Borrow SQL statement to insert data ? |