以下函數用於php中的登錄頁面。它顯示一個錯誤嘗試在PHP PDO中獲取非對象的屬性
「試圖讓....非對象的財產」
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;
}
誰能幫我..我是新來的PHP。請幫助提前
感謝
感謝@Saty修復代碼。你的SQL查詢是錯誤的。 – Jimmy
你能解釋一下查詢中有什麼錯誤嗎?@ Jimmy – Saty
我的查詢有什麼問題? –