Following function I used in a login page in php. Its showing a error that
" Trying to get property of non-object in...."
function Validate($userName,$encrypted_password,$dbh)
{
try{
echo ("".$userName."");
echo ("".$encrypted_password."");
$sql = "SELECT USERCODE,PWD FROM GUSER WHERE USERCODE = :uname AND PWD = :pwd";
echo $sql->error;
$query = $dbh->prepare($sql);
$query->bindParam(':uname',$userName,PDO::PARAM_STR);
$query->bindParam(':pwd',$encrypted_password,PDO::PARAM_STR);
$query->execute();
$rows = $query->fetch(PDO::FETCH_NUM);
echo ("".$rows."");
if($rows > 0){
echo "Login Successfull";
header("location: home.php");
}
else{
$errmsg_arr[] = 'Username and Password are not found';
$errflag = true;
}
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
echo "Closed";
exit();
}
}
catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
//return $getValue;
}
Can anyone help me out.. I am new to php.. Please help
Thanks in advance