When I try to insert the start line of a table that will track daily views, I get an error:
Fatal error : call of bind_param () member function for non-object in /.../functions.php on line 157 strong>
This line is the last of the following groups:
if($stats_found) {
$sqlquery = "UPDATE vid_stats SET views = ? WHERE title = ? AND format = ? AND date = ? AND results = ?";
$views++;
} else {
$sqlquery = "INSERT INTO vid_stats (views, title, format, results) values (?, ?, ?, ? )";
$views = 1;
}
$stmt = $mysqli->prepare($sqlquery);
$stmt->bind_param("dsss", $views, $title, $format, "success");
Any hints of a problem?
Just in case, this is a problem with the surrounding code, here is the full function:
function updateViewCount($title, $format, $results) {
global $mysqli;
$views = 0;
if ($stmt = $mysqli->prepare("SELECT views FROM vid_stats WHERE title = ? AND format = ? AND date = ?")) {
$stmt->bind_param("ssd", $title, $format, date("Y-m-d"));
$stmt->execute();
$stmt->bind_result($views);
if ($stmt->fetch()) {
$stats_found = true;
} else { $stats_found = false; }
$stmt->close();
if($stats_found) {
$sqlquery = "UPDATE vid_stats SET views = ? WHERE title = ? AND format = ? AND date = ? AND results = ?";
$views++;
} else {
$sqlquery = "INSERT INTO vid_stats (views, title, format, results) values (?, ?, ?, ? )";
$views = 1;
}
$stmt = $mysqli->prepare($sqlquery);
echo $sqlquery."<br>".$views."<br>".$title."<br>".$format;
$stmt->bind_param("dsss", $views, $title, $format, "success");
$stmt->execute();
$stmt->close();
}
}