PHP has written a simple user registration page. This article combines the contents of the previous article, the information submitted on the registration page post to the following page register.php, register.php will post the information submitted to the storage.
First, create DATABASE and table structure
1, build the library
Mysql> CREATE database 361way character set UTF8;
Query OK, 1 row Affected (0.00 sec)
Above I built a same life with my Site 361way library.
2. CREATE TABLE structure
CREATE TABLE IF not EXISTS ' Tblmember ' (
' id ' int (one) not NULL auto_increment,
' fName ' varchar not NULL,
' lName ' varchar not NULL,
' Email ' varchar not NULL,
' Password ' varchar not NULL,
' Birthdate ' text not NULL,
' Gender ' varchar not NULL,
PRIMARY KEY (' id ')
) Engine=innodb DEFAULT Charset=utf8 auto_increment=10;
Here the character encoding I selected is UTF8, and in the table ID value is starting from 11 (reserved 10), database engine type of INNODB, specific can be modified according to their own needs.
Second, post submit PHP page
The register.php code for submitting a POST request to the back end is as follows:
<?php
Set up MySQL connection
mysql_connect ("localhost", "root", "123456") or Die (Mysql_error ());
Select Database
mysql_select_db ("361way") or Die (Mysql_error ());
Get the ' value from the ' posted data and store it to a respected variable
$fName = $_post[' fName '];
$lName = $_post[' lName '];
$email = $_post[' email '];
$reemail = $_post[' Reemail '];
$password = SHA1 ($_post[' password '));
$month = $_post[' month '];
$day = $_post[' Day '];
$year = $_post[' year '];
$gender = $_post[' Optionsradios '];
$birthdate = $year. '-' . $month. '-' . $day;
Insert data using INSERT INTO statement
$query = "INSERT into Tblmember (ID, fName, lName, email, password, birthdate, gender)
VALUES (NULL, ' {$fName} ', ' {$lName} ', ' {$email} ', ' {$password} ', ' {$birthdate} ', ' {$gender} ');
Execute the query
if (mysql_query ($query)) {
Dislay a message box This saving is successfully save
echo "<script type=\" text/javascript\ ">
Alert (\ "New member added successfully.\");
Window.location = \ "Registration.php\"
</script> ";
} else
Die ("Failed:"). Mysql_error ());
?>
When the above code is used, the username password and library name of the database are modified according to the actual situation.
Third, test code
After entering the relevant information and submitting it in the previous registration page, the following message will pop up to indicate successful registration:
Register-mysql
And look at the information in MySQL:
Mysql> select * from Tblmember;
+----+-------+-------+------------------+------------------------------------------+-------------+--------+
| ID | FName | LName | email | password | Birthdate | Gender |
+----+-------+-------+------------------+------------------------------------------+-------------+--------+
| 10 | Test | Yang | admin@361way.com | A94a8fe5ccb19ba61c4c0873d391e987982fbbd3 | 1997-jan-28 | Female |
| 11 | AAA | BBB | test@91it.org | 54df472f438b86fc96d68b8454183394ef26b8ac | 1997-jan-18 | Female |
+----+-------+-------+------------------+------------------------------------------+-------------+--------+
2 rows in Set (0.00 sec)
I have performed two registrations, and here are two records.