试图获得非对象的属性

时间:2014-04-06 21:38:42

标签: php

我想如果没有作者/用户找到退出给出下面的消息。但继续引人注目试图在$ author_found_count上获取非对象的属性。为什么是这样?感谢

$find_author = "SELECT user FROM reviews WHERE review_id=$review_id;";

$search_author = mysqli_query($con,$find_author);

$found_author = mysqli_fetch_array($search_author);

$author_found_count = $found_author->num_rows;

//Check to see if any reviews have been found.
if($author_found_count == 0) {

//No reviews found.
exit ("You are not the author of the review. You are not authorised to delete it.");
}

3 个答案:

答案 0 :(得分:1)

这是因为num_rows不是结果集的属性。请改为$author_found_count = $search_author->num_rows;

答案 1 :(得分:0)

您正在尝试获取php数组的num_rows,但为此您应该使用mysqli_result对象:

$author_found_count = $search_author->num_rows;

您还可以使用php函数检查结果集是否为空:

$author_found_count = count($found_author);

答案 2 :(得分:0)

因为它是一个数组,应该像这样访问:查看文档: http://us2.php.net/manual/en/mysqli-result.fetch-array.php