PHP to make user registration system _php Skills

Source: Internet
Author: User
Tags md5

So far, you've learned a lot about PHP. It's time to write a small program practicing.

User Registration System

Write a index.php page with user name and password form, post submit to check.php, output username and "username + password" MD5 value
Local set up a MySQL database, named Segmentfault, set up a table user, field username password will be on the title check.php received the content deposited
Let's finish the HTML section first:

<! DOCTYPE html>
 
 

Note that HTML5 's support for forms is much better than previous versions of HTML, and can be used to indicate various types directly. For example, the establishment of type= "email", will verify that the user submitted the e-mail address is legitimate.

And then the check.php.

<! doctype>

 
 

Here is the PHP section, which embeds HTML directly, which is the advantage of PHP:

<?php 
$username = htmlspecialchars ($_post["name"));
echo $username;
? >
</p>
<p> your "Mailbox + password" MD5 value is:
<?php
$passphrase = Htmlspecialchars ($_post[" Passphrase "]);
$MD 5sum = MD5 ($username. $passphrase);
echo $MD 5sum;

Note that we use the htmlspecialchars to avoid the user from filling in strange things.

Then the database operation, we use mysqli, (MySQL has been discarded, now recommended to use 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 normal:

$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 Code code as follows:
$sql = "CREATE TABLE User (username char (140), password char (140))";

Add a record

Copy Code code as follows:
Mysqli_query ($conn, "INSERT into user (username, password) VALUES ($username, $MD 5sum)");

Handwriting sql is not very cool, in practical applications, the framework will provide you with a variety of convenience.

To close the database:

Mysqli_close ($conn);

? >
</p>
</body>

 
 

Well, we've successfully written a small application and incidentally learned how to access the MySQL database. That's it for today.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.