This php login code is always unsuccessful. See where the problem is.

Source: Internet
Author: User
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 ......

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.