0

Why doesnt this code work. I keep getting false even when i type in the correct username and password

$user_name = mysql_query("SELECT * FROM users WHERE username =
                                           '".$Entered_UserName ."' 
                                           AND password = '".md5($Entered_PassWord) . "'");

         $user_name_password = mysql_fetch_assoc($user_name);

         if($user_name_password === false)
           {
           	echo 'false';
           }
         else
           echo 'true';
         }
4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by cwarn23
0

Why doesnt this code work. I keep getting false even when i type in the correct username and password

Try this (I didn't test it)

$user_name = mysql_query("SELECT * FROM users WHERE username = {'$Entered_UserName'}  AND password =  '{md5($Entered_PassWord)}' ");

         $user_name_password = mysql_fetch_assoc($user_name);

         if($user_name_password)
           {
           	echo True';
           }
         else
           echo 'False';
         }
0

Why doesnt this code work. I keep getting false even when i type in the correct username and password

$user_name = mysql_query("SELECT * FROM users WHERE username =
                                           '".$Entered_UserName ."' 
                                           AND password = '".md5($Entered_PassWord) . "'");

         $user_name_password = mysql_fetch_assoc($user_name);

         if($user_name_password === false)
           {
           	echo 'false';
           }
         else
           echo 'true';
         }

are you sure that you are md5 encrypting the password when you are storing it to the database, when the user first time enters it, while registration.

0

Try the following:

$user_name = mysql_query('SELECT * FROM users WHERE username ="'.mysql_real_escape_string($Entered_UserName).'" AND password = "'.md5($Entered_PassWord).'"') or die(mysql_error());

         $user_name_password = mysql_fetch_assoc($user_name);

         if($user_name_password === false)
           {
           	echo 'false';
           } else{
           echo 'true';
         }

Edited by cwarn23: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.