In order to achieve faster performance, our code interface has not been beautified. We will guide you through user registration as quickly as possible.
1. Determine repeated passwords
Because there are repeated passwords, if the passwords entered by the user twice are inconsistent, it means whether the password has been entered. Any sense of the next step.
Repeated passwords are still used in many places on the web page. Because the fear is that users will make mistakes. The password was entered incorrectly.
Users may enter two more spaces on the left and right sides when entering their password. Therefore, we will use trim to remove spaces from both sides of passwords and repeated passwords.
We need to write both the user's input data and hidden data to the database.
The visible data are:
Variables
Description
$_POST['username']
## Username
$_POST['password']
Password
We need to remove the spaces on both sides of the username to avoid entering unnecessary information.
In the mysql chapter, we have said that the user's password should not be visible to people including company insiders. Ensure that the password is irreversible. At the initial stage, just learn MD5. We will teach you other encryption methods in the future.
Invisible data includes:
## Variable
Description
##$time
User registration time
##$_SERVER['REMOTE_ADDR']
User’s registered IP
The unix timestamp returned by time
REMOTE_ADDR returns the IP address, which we can use ip2long to convert to integer storage.
And our statement to create the table is as follows:
CREATE TABLE IF NOT EXISTS user (
id int(11) NOT NULL,
username varchar(30) NOT NULL,
password char(32) NOT NULL,
createtime int(11) NOT NULL,
createip int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Format of the table (field corresponding description):
id
username
##password
createtime
createip
##User ID
Username
Password
Creation time
Create IP
5. Send a statement and determine the status
mysqli_query As we said above, two parameters need to be passed in:
Connected resources, the corresponding variable here is $conn.
The SQL statement sent. $sql is already prepared above.
SQL statements can be sent to the MySQL server through mysqli_query. $result is true if sent successfully. Otherwise false.
If successful, we can prompt the user that the registration is successful.
In some cases, mysqli_insert_id() may also need to be used. Print the auto-incremented primary key ID here.
Please remember this knowledge point to avoid forgetting it when needed in the future.
mysqli_insert_id application scenario: newly added row of data. We need to get the automatically growing ID value when inserting this ID value into another table. You need to use this function.
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning