PHP creates a user registration system and php creates a user registration _ PHP Tutorial

Source: Internet
Author: User
PHP creates a user registration system, and php creates user registration. PHP creates a user registration system. you have learned a lot about php so far. It's time to write a small program. User registration system write an index. php page PHP production User registration system php production User registration system

So far, you have learned enough about PHP. It's time to write a small program.

User registration system

Write an index. php page with a user name and password form. submit the post to check. php and output the md5 values of the user name and "user name + Password ".
Create a local mysql database named segmentfault and create a table user. the username password field stores the content received by check. php.
Complete the HTML section first:

RegisterRegister

Note: HTML5 supports forms much better than HTML in previous versions. you can directly specify various types. For example, if type = "email" is set, the system checks whether the email address submitted by the user is valid.

Check. php.

Registered successfully!Wow, you have registered successfully!

Er ...... However, it seems that registration is useless because the website does not have any other functions except registration.

So, as compensation, I will tell you the md5 value of your "mailbox + Password.

Your email address is:

Below is the PHP part, which is embedded directly into HTML, which is the advantage of PHP:

<? Php $ username = htmlspecialchars ($ _ POST ["name"]); echo $ username;?>

The md5 value of your "email + password" is: <? Php $ passphrase = htmlspecialchars ($ _ POST ["passphrase"]); $ md5sum = md5 ($ username. $ passphrase); echo $ md5sum;

Note that htmlspecialchars is used to prevent users from entering strange things.

Next, we use mysqli for database operations. (mysql has been deprecated. now mysqli is recommended. of course you can also use PDO .)

First, we specify some information about the database:

$db_server = "localhost";$db_user = "db_user";$db_pass = "password";$db_name = "segmentfault";

Connect to the database and ensure 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

The code is as follows: $ SQL = "CREATE TABLE user (username CHAR (140), password CHAR (140 ))";

Add record

The code is as follows: mysqli_query ($ conn, "insert into user (username, password) VALUES ($ username, $ md5sum )");

Handwriting SQL is not very good. in actual application, the framework will provide you with various conveniences.

Close the database:

mysqli_close($conn);?>

Well, we have successfully written a small application and learned how to access the MySQL database. This is today.

So far, you have learned enough about PHP. It's time to write a small program. The user registration system writes an index. php page...

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.