Welcome to the Linux community forum, and interact with 2 million technical staff to enter user registration and login is one of the most basic functional modules of website development, now, you can log on to the handler code to learn some basic php operations on mysql. There is no difficulty in writing the basic code. As a developer, you should be able to write the basic code to improve your memory.
Welcome to the Linux community forum and interact with 2 million technical staff> entering user registration and logon is one of the most basic functional modules of website development, now, you can log on to the handler code to learn some basic php operations on mysql. There is no difficulty in writing the basic code. As a developer, you should be able to write the basic code to improve your memory.
Welcome to the Linux community forum and interact with 2 million technicians>
User Registration and login are one of the most basic functional modules of website development. Now, you can learn some basic php operations on mysql by logging on to the processing code.
There is no difficulty in writing the basic code. As a developer, you should be able to write the basic code on your own to enhance your memory. At the same time, you may wish to provide some reference for beginners.
When php connects to the MySQL database server, there are three main APIs available:
MySQL extension in PHP
Mysqli extension of PHP
PHP Data Object (PDO)
// Receives user login window input data
$ Username = $ _ POST ['username'];
$ Password = $ _ POST ['Password'];
// Connect to the database
$ Conn = mysql_connect ('dbip', 'dbuser', 'dbpassword ');
If (! $ Conn ){
Dir ('Connection failed'. mysql_errno ());
}
// Sets the encoding method of the Access database.
Mysql_query ("set names utf8", $ conn) or dir (failed to set encoding '. mysql_errno ());
// Select a database
Mysql_select_db ("dbname", $ conn) or dir ('database selection failed'. mysql_errno ());
// Send SQL statements to prevent SQL Injection
$ SQL = "select password, nickname from tb_user where username = '$ username '";
$ Res = mysql_query ($ SQL, $ conn );
// If data exists
If ($ row = mysql_fetch_assoc ($ res )){
// Determine the password
If ($ password = md5 ($ row ['Password']) {
// Valid user
$ Nickname = $ row ['nickname'];
Header ("Location: success. php? Nickname = $ nickname ");
Exit ();
}
}
// The user or password is incorrect.
// The current website no longer prompts the user whether the user name is wrong or the password is wrong, so as to avoid targeted password cracking by hackers
Header ("Location: failed. php ");
Exit ();
// You must also consider disabling resources and connections. Pay attention to the code location.
// Mysql_free_result ($ res );
// Mysql_close ($ conn );
?>
Other knowledge:
Multiple records are displayed on the list page.
If ($ row = mysql_fetch_assoc ($ res), change it to while ($ row = mysql_fetch_assoc ($ res )).