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 );