hello everyone , This is Nate PHP, Give some lessons today PHP A friend who is just getting started introduces one to use PHP When writing backstage , Make a simple login and registration page .

First, we need to configure a PHP Environment , In fact, there are many tools that can help you do this at one time , It seems that I often use it PHPSTUDY, I've used it before WAMP And other tools , But I still recommend it personally PHPSTUDY, You can directly go to its official website to download , Now the new version PHPSTUDY It's getting more and more stupid ~~ Basically, you don't need to configure some by yourself conf File .

In addition, make sure the system is installed before installation Visual C++, If it is a complete version of the system, it is basically installed , If it is not installed, the system will prompt that it is missing msvcr100.dll This file .

How to deal with this problem can be directly Baidu , It's simple .

The next step is to start PHPSTUDY Yes , This is also relatively simple , Now it's basically a visual interface , You don't have to modify it HOST and VHOST These documents are missing .

Building a database is also a relatively simple thing , Can be used directly PHPSTUDY Built in MYSQL management tool , You can also download one PHPMYADMIN Just put it under the directory of any virtual station and you can access it .

When everything is ready, we will move on to what we want to talk about today , use PHP Write a background for login and registration .

We can simulate a domain name , such as www.nt.com, Just use a domain name here .

Use the methods taught in the articles between us , Write a simple PHP page , It can also be written like this :

echo phpinfo();

?>

If this page is accessed successfully , That means the preparations have been made .

Next, go to PHPMYADMIN Page of , Build a database , The interface is like this .

HTML The code of the page is like this .
User login profile
Introduction to user login page

Then select from the list on the left new Create a new database ( Don't move the others ), Here we first create a file named manage Database of , Character encoding is set to utf8_general_ci

After the creation is successful, there will be one more list on the left manage Options for , This is the database we just created . Click this manage Start creating data table , The table name is set to admin, The number of fields is temporarily set to 5, This field number represents each of your user Number of attributes to set ( You will know when you set the field later ), After execution, you will enter the following page

You can see that there are only five lines to fill in , This is the number of fields we set in the previous step 5, If you want to add more fields, you can select add fields at the top of the page . Here is a brief explanation of the attributes in each field : The name is everyone user The name of the property , such as ID, Gender , Password, etc ; Type is to select the data type ; Length determines the maximum length of the field ( There is an upper limit ); The default is the initial value of this field ; I usually choose sorting rules, that is, coding rules utf8; Set binary in property , Unsigned type, etc ; If blank is selected, this field is allowed to be blank , If it is not selected, it cannot be empty ; Select primary key search in index , Full text search, etc ;A_I If checked, it means auto increment ; Notes are notes, which is easy to understand . After saying that, many Xiaobai may be confused , Don't worry, we will understand it through practical operation . Here I set number,user_id,user_sex,user_password Four fields , See the chart for each attribute .

After setting, you will go to the following page , You can see me number I chose A_I That is, self increase , And in number This column and that place are also gray , It means default number As primary key , You need to explain the primary key , The primary key value is a column or a combination of columns , Its value uniquely identifies each row in the table , It allows you to enforce the physical integrity of a table . Primary keys are mainly used for foreign key Association of other tables , And the modification and deletion of this record . Note that the primary key has no practical significance in business in real application , It won't be so simple , Sometimes it's used GUID Or other , My settings here are just a demonstration .

After the data table fields are set, we can start writing PHP Code , Before writing, first add two users to the database , Here we select the Insert tab , Then fill in the relevant attributes , First I set number by 1, Others are the default , I won't fill in the second one number, Modify other information . Finally, select browse to view the two users just inserted .

In addition, we need to write another page of database connection ,conn.php

Here's the code

$link=new PDO("mysql:host=localhost;port=3306;dbname=db","root","");

$link->query("set names utf8");

register phpstudy The default database connection account and password are root

These are about how to use PHP Build a simple login registration page , I hope you can understand and master this knowledge from your study .

Technology
Daily Recommendation