How to write the code for user logon?-php Tutorial

Source: Internet
Author: User
How to write the code for user login .. & Lt ;? Phpsession_start ();? & Gt; & lt ;! DOCTYPE & nbsp; html & nbsp; PUBLIC & nbsp;-W3CDTD & nbsp; XHTML & nbsp; 1.0 & nbsp; TransitionalEN & nbsp; www. how to write the code for w3.orgTRxhtml1DTD user logon ..
Session_start ();
?>
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>


/>



Header ("Content-Type: text/html; charset = UTF-8 ");
// Connect to the database
Mysql_connect ("localhost", "root ","");
Mysql_select_db ("db12 ");
/** This file is used to receive user input information for query and determine whether the file exists.
Go to the success page. If an error occurs, an error message is displayed. */
// Accept user parameters (username and password)
$ User = $ _ POST ['username'];
$ Pass = $ _ POST ['password'];
// Query by user name and retrieve the password
$ SQL = "select password from tb_user where username = '". $ user ."'";

// Execute the query
$ Rs = mysql_query ($ SQL );
If ($ rs! = ""){
$ Selpass = mysql_result ($ rs, 0 );
}
If ($ selpass! = ''){
// Determine whether the obtained password is consistent with that entered by the user
If ($ pass = $ selpass ){
$ _ SESSION ['username'] = $ user;
?>
Script
// If the logon is successful
Alert ("login successful! ");
// Go to the homepage
Location. href = "index. php ";
Script
} Else {
// Password error prompt
?>
Script
// If the logon is successful
Alert ("incorrect password, think about it! ");
// Go to the homepage
Location. href = "login. php ";
Script
}
} Else {
// If no information is found based on the user name, the system prompts that the user name does not exist.
?>
Script
// If the logon is successful
Alert ("the user name you entered does not exist. Please verify it! ");
// Go to the homepage
Location. href = "login. php ";
Script
}
?>


The above is the code for processing user login,
Why is this displayed on the logon page whether entered correctly or incorrectly:


------ Solution --------------------
Print_r () doesn't you know what's going on with your username and password!
------ Solution --------------------
Why not? Your second form does not have the username and password controls at all. of course, an error is returned.
Print_r ($ _ POST );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.