【发布时间】:2015-09-05 10:18:26
【问题描述】:
我在 php.ini 的登录页面中使用了以下函数。它显示一个错误,
" 试图在...中获取非对象的属性"
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
-
我的查询有什么问题??
-
是的。您的查询有误。
-
那些说他的问题是错误的——你怎么知道的? :D 你们甚至阅读并理解了他遇到的问题和错误,或者您只是开始输入 cmets?