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.