I'm doing a verify login in php and when i put my username and password correctly. It prompts 'Incorrect UserName Password'
?php
$user = $_POST ['txtuname'];
$pass = $_POST ['txtpass'];
$encryptpass=md5($pass);
// used mysql_connect_db instead of mysql_connect
mysql_connect("localhost", "root", "") or die(mysql_error());
// This line is missing
mysql_select_db("intranet") or die(mysql_error());
// pass= ' " . $pass . " ' " ----> contains space resulting to incorrect pass
//$sql = "SELECT * FROM employee WHERE uname = " . $user . " and pswrd = " . $pass . "";
$sql= "SELECT * FROM employee WHERE uname='$user' and pswrd='$encryptpass'";
$rs = mysql_query($sql) or die(mysql_error());
if(mysql_affected_rows() > 0)
{
$row =mysql_fetch_array ($rs);
echo "name: " . $row['fname'] . " " . $row['lname'];
}
else
{
echo "Incorrect Username or Password";
}
?>
Thank You for helping!