This php login code is always unsuccessful. Please see where is the problem? & Lt ;? Php & nbsp; session_start (); & nbsp; $ conn = mysql_connect ("localhost", "admin", "admin") & nbsp; or & nbsp; d. The php login code is always unsuccessful. Please see where is the problem?
Session_start ();
$ Conn = mysql_connect ("localhost", "admin", "admin") or die ("database link error". mysql_error ());
Mysql_select_db ('member', $ conn) or die ("wrong database selection". mysql_error ());
Define (ALL_PS, "php123 ");
If ($ _ POST [submit])
{
$ Username = str_replace ("", "", $ _ POST [username]);
$ SQL = "select * from user_list where 'username' = '$ username '";
$ Query = mysql_query ($ SQL );
$ Ps = $ us? Md5 ($ _ POST [password]. ALL_PS) = $ row [password]: FALSE;
If ($ ps ){
$ _ SESSION [uid] = $ row [uid];
$ _ SESSION [user_shell] = md5 ($ row [username]. $ row [password]. ALL_PS );
Echo "OK ";
} Else {
Echo "no ";
}
}
?>
Always output no
------ Solution --------------------
If ($ ps ){???
In your code, $ ps has no chance of being true, so you can only output no
In the code, the only one with a value for $ ps is
$ Ps = $ us? Md5 ($ _ POST [password]. ALL_PS) = $ row [password]: FALSE;
Because $ us is not assigned a value, $ ps can only be FALSE.
If ($ _ POST [submit])
{
$ Username = str_replace ("", "", $ _ POST [username]);
$ SQL = "select * from user_list where 'username' = '$ username '";
$ Query = mysql_query ($ SQL );
$ Ps = $ us? Md5 ($ _ POST [password]. ALL_PS) = $ row ['password']: FALSE;
Writing:
if($_POST['submit'])
{
$username=str_replace(" ","",$_POST['username']);
$sql="select * from user_list where `username` ='$username'";
$query=mysql_query($sql);
$row = mysql_fetch_assoc($query);
$ps = $row['username'] ? md5($_POST['password'].ALL_PS)==$row[password] : FALSE;
------ Solution --------------------
$ SQL = "select * from user_list where 'username' = '$ username '";
Remove the single quotes.
------ Solution --------------------
$ _ POST ['username']
These two are written as the same
------ Solution --------------------
$ SQL = "select * from user_list where 'username' = '". $ username ."'";
------ Solution --------------------
Var_dump ($ row); check whether there is any data
------ Solution --------------------
Your code may have multiple errors.
You try it one by one, and you will never find the reason...
You can print your value with var_dump step by step to see the result.
We just want to help you analyze the possible causes.
------ Solution --------------------
Reference:
Echo var_dump ($ row); result output: bool (false)
Is the following code a problem?
PHP code? 1234 $ username = str_replace ("", "", $ _ POST [username]); $ SQL = "select * from user_list where 'username' = '$ username '"; $ query ......