There is code to check if the user has entered the right password or not.
if (isset($_POST['userpassword']))
{
include('db.php');
//I have used the name passwordu instead of password in the database as well.
$query = "SELECT * FROM users WHERE username = '".$_REQUEST['username']."' AND passwordu = '".md5($_REQUEST['userpassword'])."';";
$result = mysql_query($query);
if ($result){ //THIS IS WHERE I FEEL THE ERROR IS
echo "Congratulations. You are now Logged in. You will be logged out when the Browser is closed.";
$_SESSION['logval'] = TRUE; //Sets the User Logged in for the complete session.
}
else echo "Sorry, You Entered Wrong Info.";
}
However, even if a wrong password is entered it accepts the log in.
What is wrong here?
Also, if I am making a conceptual mistake, please tell me the right way to check if the user has entered the right information.
To be completely honest – what is wrong is the code is allowing MySQL Injections
But for your code, use mysql_num_rows().
mysql_query() returns true if the query was successful. false if not.
mysql_num_rows() counts the rows.