Logging on to the registration system is the most common operation for daily Internet access. I have set up a classification to improve the registration and logon system step by step. If there is any error, please forgive me. Language used: php Database: mysql this implementation function: 1. user Registration 2. Main user login file: complete code 1sql create user table, id, username, password 3 in the existing database
Logging on to the registration system is the most common operation for daily Internet access. I have set up a classification to improve the registration and logon system step by step. If there is any error, please forgive me. Language used: php Database: mysql implementation function: 1. user Registration 2. main user login file: complete code 1 SQL creates the user table, id, username, password three in the existing database
Logging on to the registration system is the most common operation for daily Internet access. I have set up a classification to improve the registration and logon system step by step. If there is any error, please forgive me.
Language used:Php
Database:Mysql
This implementation function:
1. User Registration
2. User Logon
Main files:
Complete code
1. SQL creates the user table, id, username, and password fields in an existing database.
The Code is as follows:
Create table user (id int (10) not null auto_increment, username varchar (30), password varchar (40), primary key (id ));
2 connect. php Database Configuration File
<? Php $ server = "localhost"; // host $ db_username = ""; // your database username $ db_password = ""; // Your Database Password $ con = mysql_connect ($ server, $ db_username, $ db_password); // link to the database if (! $ Con) {die ("can't connect ". mysql_error (); // if the link fails to output an error} mysql_select_db ('test', $ con); // select the database (my name is test)?>
3 signup.html registry ticket
User registration page
4 signup. php Registration Program
<? Php header ("Content-Type: text/html; charset = utf8"); if (! Isset ($ _ POST ['submit ']) {exit ("error execution ");} // determine whether there is a submit operation $ name =$ _ POST ['name']; // obtain the name $ password in the form using post =$ _ POST ['Password']; // post to obtain the password include ('connect. php '); // connect to the database $ q = "insert into user (id, username, password) values (null,' $ name', '$ password ')"; // Insert the SQL $ reslut = mysql_query ($ q, $ con) from the form to the database; // Execute SQL if (! $ Reslut) {die ('error :'. mysql_error (); // If the SQL Execution fails to output an error} else {echo "registered successfully"; // The output is successfully registered} mysql_close ($ con ); // close the database?>
The registration process is complete. The following figure shows the user logon process.
5 login.html login form
Login
6 login. php login program
<? PHP header ("Content-Type: text/html; charset = utf8"); if (! Isset ($ _ POST ["submit"]) {exit ("misexecuted");} // checks whether the submit operation include ('connect. php '); // link to the database $ name =$ _ POST ['name']; // obtain the username form value from post $ passowrd =$ _ POST ['Password']; // post to obtain the single user password value if ($ name & $ passowrd) {// If neither user name nor password is blank $ SQL = "select * from user where username = '$ name' and password =' $ passowrd '"; // check whether the database has the corresponding username and password SQL $ result = mysql_query ($ SQL); // Execute SQL $ rows = mysql_num_rows ($ result ); // returns a value if ($ Rows) {// 0 false 1 true header ("refresh: 01_url1_welcome.html"); // if it succeeds, exit from the welcome.html page;} else {echo "incorrect user name or password "; echo "script" settimeout(function({{w.location.href}'login.html ';}, 1000); script "; // if the error occurs, jump to the logon page 1 second and try again ;}} else {// if the user name or password is empty, echo "the form is not complete"; echo "script" settimeout(function({{{location.href}'login.html ';}, 1000); script "; // skip to the logon page one second after js is used incorrectly and try again.} mysql_close (); // Close the database?>
7. Successful Logon to welcome.html
Login successful Welcome
So far, a simple and complete registration and login system has been completed, and the code is very simple without considering the security robustness of the verification, which will be improved later.
I hope this article will help you learn php programming.