0
I have the following function:
function sql_update_views ($table = null, $id = null) {
$database = open_database();
$found = null;
try {
$sql = "UPDATE ".$table." SET views = views + 1 WHERE id = ".$id;
$result = $database -> query($sql);
if ($result -> num_rows > 0) {
$found = $result -> fetch_all(MYSQLI_ASSOC);
}
}
catch (Exception $e) {
$_SESSION['message'] = $e -> GetMessage();
$_SESSION['type'] = 'danger';
}
close_database($database);
return $found;
}
I get the following error:
Notice: Trying to get Property of non-object in D: xampp htdocs armazemdahouse include database.php on line 167
If I apply the solution contained in the question:
I get the error:
Notice: Undefined variable: num_rows in D: xampp htdocs armazemdahouse include database.php on line 167
What is the solution?
I realized that if the user accesses the page and keeps pressing F5 then the views of the publication will increase in a non cordial way. Where I should do the treatment so that this type of situation is blocked, by IP in another table?
Read this: https://pt.meta.stackoverflow.com/a/5510/132
– Victor Stafusa