This article mainly introduces the PHP production user registration system detailed code, the interested friend's reference, hoped to be helpful to everybody.
User Registration System
Write a index.php page with username and password form, post to check.php, output user name and MD5 value of Username + password
Build a MySQL database locally, named Segmentfault, create a table user, field username password The contents of the previous question check.php receive
Let's complete the HTML section first:
<! DOCTYPE html>
Note that HTML5 support for forms is much better than previous versions of HTML, and can directly indicate various types. For example, the establishment of type= "email", will verify the user submitted email address is legitimate.
And then the check.php.
<! Doctype>
The following is the PHP section, directly embedded in HTML, which is the advantage of PHP:
<?php $username = htmlspecialchars ($_post["name"); Echo $username;? ></p><p> your "email + password" MD5 value is: <?php$passphrase = Htmlspecialchars ($_post["passphrase"]); $MD 5sum = MD5 ( $username. $passphrase); Echo $MD 5sum;
Note that we used Htmlspecialchars to avoid the user filling in strange things.
Then is the database operation, we use mysqli, (MySQL is obsolete, now recommended with mysqli, of course you can also use PDO.) )
First we indicate some information about the database:
$db _server = "localhost"; $db _user = "Db_user"; $db _pass = "password"; $db _name = "Segmentfault";
Connect to the database and make sure the connection is OK:
$conn = new Mysqli ($db _server, $db _user, $db _pass, $db _name), if (Mysqli_connect_errno ()) {Trigger_error ("Database Connection failed: ". Mysqli_connect_error (), e_user_error);}
Create a table using SQL statements
The code is as follows:
$sql = "CREATE TABLE user (username char, password char (140))";
Add a record
The code is as follows:
Mysqli_query ($conn, "INSERT into user (username, password) VALUES ($username, $MD 5sum)");
Handwritten SQL is not very cool, in practice, the framework will provide you with a variety of convenience.
To close the database:
Mysqli_close ($conn);? ></p></body>
Summary: The above is the entire content of this article, I hope to be able to help you learn.