2 回答
TA贡献1772条经验 获得超8个赞
基于该错误,您没有result
在$result
变量中获取该值。要检查这一点,您可以使用:
if (isset($result['result']) && count($result['result']) > 0)
首先检查该值是否已设置。
您还需要调查为什么无法从数据库中获得预期的结果。为此,您将需要查看$result
变量中返回的内容,并查找数据库查询可能返回的任何错误。
TA贡献1842条经验 获得超12个赞
function login($user, $pass) {
// try to match a row in the "login" table for the given username and password
$result = query("SELECT IdUser, username FROM login WHERE username='%s' AND pass='%s' limit 1", $user, $pass);
$rows=$result->num_rows;
//Line 43
if ($rows>0) {
// a row was found in the database for username/pass combination
// save a simple flag in the user session, so the server remembers that the user is authorized
$_SESSION['IdUser'] = $result['result'][0]['IdUser'];
// print out the JSON of the user data to the iPhone app; it looks like this:
// {IdUser:1, username: "Name"}
print json_encode($result);
} else {
// no matching username/password was found in the login table
errorJson('Authorization failed');
}
}
- 2 回答
- 0 关注
- 153 浏览
添加回答
举报