可能重复:
Warning: mysql_fetch_* expects parameter 1 to be resource, boolean given error
第110行是mysqli_free_result($r);
有人可以解释我在这里做错了什么以及如何解决?
以下是代码的一部分。
if(isset($user_pass) && ($user_pass == TRUE) && !empty($salt)) {
$q = "SELECT users.user_id, users.first_name, users.user_level FROM users JOIN contact_info ON contact_info.user_id = users.user_id WHERE (contact_info.email = '" . $e . "' OR users.username = '" . $e . "') AND users.password = '" . $sha512 . "' AND users.active IS NULL";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
while($row = mysqli_fetch_array($r)){
$approved = $row['user_id'];
}
if ((@mysqli_num_rows($r) == 1 && $approved == 2)) {
$_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC);
// check if user is logged in then update the old login date
$u = "UPDATE users JOIN contact_info ON contact_info.user_id = users.user_id SET users.last_login = NOW(), users.deletion = 0, users.deletion_date = NULL WHERE (contact_info.email = '" . $e . "' OR users.username = '" . $e . "') AND users.password = '" . $sha512 . "' AND users.active IS NULL";
// save the info to the database
$r = mysqli_query ($dbc, $u);
mysqli_free_result($r);
mysqli_close($dbc);
exit();
} else {
echo 'Error;
}
} else {
echo 'Error';
}
答案 0 :(得分:2)
不确定某些查询(例如INSERT)是否返回false?请更正我,因为我确信这发生在之前的php / mysql
中答案 1 :(得分:1)
这是因为您的查询失败了。您应该能够使用以下方式获取错误:
if( !$r )
echo mysqli_error($dbc)
此外,由于您使用的是MySQLi,也许您应该考虑通过prepared statements使用参数化查询。
答案 2 :(得分:0)
_free_result()
调用。