Use PHP to implement a simple user registration form example and php to implement registration form example

Source: Internet
Author: User

Use PHP to implement a simple user registration form example and php to implement registration form example

1. display the user information table of a single row

First, we need to create two files: an html file and a PHP file.

Here, the blogger created the form.html and formHandle. php files.

The following shows the content of the two files:

Contents of form.html:

<! DOCTYPE html> 

Effect display:


Note the following:Similar to gender, interest, and city, values 0, 1, and 2 can be used to indicate different options selected by users.

The Interest Section is multi-choice, so we need to input an array to facilitate our display. All the name attributes are recorded by Hoby.

FormHandle. php file content:

<? Php $ inf =$ _ GET;?> <! Doctype html> 

Next let's test:


The final result is:


Here is a question. The above method can only store the information of one user at a time. What should I do if I want to display the user information of multiple rows?

2. display multi-row user information table

Experienced background people will say that a database is needed to store information at this time. Here, because the blogger is just learning PHP, He will replace the database with a txt file.

In form.html<form action="test2.php" method="get">

Then, a text2.php file is created, and two userinfo.txt files and userinfo. php files are created to store user information. There are three files in total.

Text2.php file content:

<?php $str = json_encode($_GET); $fh = fopen("userinfo.txt", "a"); fwrite($fh, $str."\n"); fclose($fh); ?>

Because the information submitted to the background is an array, You need to convert it to a json string.json_encode();Save the Personal Information provided by the user to the userinfo.txt file.

Userinfo. php file content:

<? Php // display page of user information (read the information in the file) $ fh = fopen ("userinfo.txt", "r");?> <! Doctype html> 

Here, we can try to enter more user information on the form.html page.

The display results are as follows:

Summary

The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.

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.