PHP Production User registration system, PHP production user Registration
So far, you've learned enough about PHP. It's time to write a small program practiced hand.
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:
RegisteredRegistered
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.
Registration Successful!Wow, you have registered successfully!
Uh...... However, registration success seems to be of no use, because this site, in addition to registration seems to have no other features.
Well, as a compensation, I will tell you the MD5 value of your "Mailbox + password".
Your e-mail address is:
The following is the PHP section, directly embedded in HTML, which is the advantage of PHP:
<?php $username = htmlspecialchars ($_post["name"); Echo $username;? >Your "Mailbox + 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
Copy the code as follows: $sql = "CREATE TABLE user (username char, password char (140))";
Add a record
Copy the Code code 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);? >
Well, we've successfully written a small application and, incidentally, learned how to access the MySQL database. It's here today.
http://www.bkjia.com/PHPjc/1063898.html www.bkjia.com true http://www.bkjia.com/PHPjc/1063898.html techarticle PHP Production User registration system, PHP production user registration So far, you have learned enough PHP. It's time to write a small program practiced hand. User Registration system Write a index.php page ...