I am a PHP newbe. I'm trying to load an array from this function:
我是一名PHP新手。我正在尝试从此函数加载数组:
funcs.php (sql returns 1 record)
funcs.php(sql返回1条记录)
function loaduser($conn, $mysql_db, $x_email, $x_password) {
$sql = "SELECT userid, userf, userl
FROM ".$mysql_db.".users
WHERE email = '".mysqli_real_escape_string($conn, $x_email)."'
AND pw = '".mysqli_real_escape_string($conn, $x_password)."'";
//echo($sql);
$Auser = $conn->query($sql);
return $Auser;
}
loaduser.php
<?php require_once("../includes/funcs.php")
$x_email = $_GET['email'];
$x_password = $_GET['password'];
$Auser = loaduser($conn, $mysql_db, $x_email, $x_password);
var_dump($Auser);
if ($Auser[0]->num_rows > 0) {
$row=mysqli_fetch_assoc($Auser);
session_start();
$_SESSION['userid'] = $row["userid"];
echo "1";
} else {
echo "0";
}
?>
but I get this error:
但我得到这个错误:
Notice: Trying to get property of non-object in loaduser.php on line 7
注意:尝试在第7行的loaduser.php中获取非对象的属性
Please help me understand the issue TQ
请帮我理解TQ的问题
EDIT - left $Auser[0] in by mistake should read $Auser->
编辑 - 错误地留下$ Auser [0]应该读$ Auser->
EDIT - this worked fine when in same file and not in a function
编辑 - 这在同一个文件中工作正常,而不是在函数中
EDIT - FIXED was db permissions issue - but no access denied error was shown
编辑 - 修复是数据库权限问题 - 但没有显示访问被拒绝错误
1 个解决方案
#1
$Auser
as a query result is not an array, so this should work:
$ Auser作为查询结果不是一个数组,所以这应该工作:
if ($Auser->num_rows > 0) {
...
}
#1
$Auser
as a query result is not an array, so this should work:
$ Auser作为查询结果不是一个数组,所以这应该工作:
if ($Auser->num_rows > 0) {
...
}