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 \ wareemdahouse \ include \ database.php on line 167
If you apply the solution contained in the question:
I get the error:
Notice: Undefined variable: num_rows in D: \ xampp \ htdocs \ wareemdahouse \ include \ database.php on line 167
What is the solution?
I noticed that if the user accesses the page and keeps pressing the F5 then the views of the publication will increase in an unfriendly way. Where should I make the treatment to block this type of situation by IP in another table?