Go to the blank page on the header (& quot; Location: empManage. php & quot;) page to find loginProcess. php: & lt ;? Php accepts user data 1.id$ id $ _ POST [& quot; id & quot;]; 2. password $ _ POST [& quot; password & quot;]; to the number header ("Location: empManage. php ") jump to the blank page and solve the problem
LoginProcess. php:
// Accept user data
// 1.id
$ Id = $ _ POST ["id"];
// 2. Password
$ Password = $ _ POST ["password"];
// Go to the database to verify the mysql extension Library mysqli Extension Library
// 1. get the connection
$ Conn = mysql_connect ("localhost", "root", "root ");
If (! $ Conn ){
Die ("link failed". mysql_errno ());
}
// Set the encoding for accessing the database
Mysql_query ("set names UTF-8", $ conn) or die (mysql_errno ());
// Select a database
Mysql_select_db ("empmanage", $ conn) or die (mysql_errno ());
// Send an SQL statement for verification
// Prevents SQL injection attacks and changes the verification logic
$ SQL = "select password from admin where id = $ id ";
// Obtain the password of the database by entering the id, and then compare it with the entered password.
$ Res = mysql_query ($ SQL, $ conn );
If ($ row = mysql_fetch_assoc ($ res )){
// Query
// Retrieve the database password
If ($ row ["password"] = md5 ($ password ))){
// Valid description
Header ("Location: empManage. php ");
}
}
Header ("Location: login. php? Errno = 1 ");
Exit ();
Mysql_free_result ($ res );
Mysql_close ($ conn );
/*
// Simple verification (not available to the database)
If ($ id = "100" & $ password = "123 "){
// Valid. jump to empManage. php
Header ("Location: empManage. php ");
// If you want to jump, you 'd better exit ()
Exit ();
} Else {
// Invalid user
Header ("Location: login. php? Errno = 1 ");
Exit ();
}
*/
?>
The code is as above. if you do not connect to the database, you can jump to empManage. php normally.
A blank page is displayed after you connect to the database. the page you jump to is loginProcess. php. what is going on? online answers !!
------ Solution --------------------
No output before header;
Must be placed in front of the page HEAD;
Check whether:
Whether the database can be normally connected;
Encoding consistency;
$ Row ["password"] and md5 ($ password) have equal values
------ Solution --------------------
I didn't see any errors in the code. I suggest you debug it first. Change header () to echo () to see if there is any output. In addition, check whether you have opened the error prompt.
------ Solution --------------------
$ Res = mysql_query ($ SQL, $ conn );
This sentence is correct.
It may cause an error in if ($ row = mysql_fetch_assoc ($ res) {because the error is not displayed, it is a blank page
------ Solution --------------------
Discussion
$ Res = mysql_query ($ SQL, $ conn );
This sentence is correct.
It may cause an error in if ($ row = mysql_fetch_assoc ($ res) {because the error is not displayed, it is a blank page