Detailed code for PHP production user registration system

Source: Internet
Author: User
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.

Related Article

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.