I am making a game for class and I have a user settings page where the admin can modify the settings.
When I click the update button I am returned with this error:
Call to a member function bind_param() on a non-object
This is the code where I believe the error is originating:
<?php
$records = array();
if (!empty($_POST)) {
if (isset($_POST['site_name'], $_POST['header_text'], $_POST['footer_copyright'], $_POST['allow_robot_name'], $_POST['default_robot_name'])) {
$site_name = $_POST['site_name'];
$header_text = $_POST['header_text'];
$footer_copyright = $_POST['footer_copyright'];
$allow_robot_name = $_POST['allow_robot_name'];
$default_robot_name = $_POST['default_robot_name'];
if (!empty($site_name) && !empty($header_text) && !empty($footer_copyright) && !empty($allow_robot_name) && !empty($default_robot_name)) {
$insert = $db->prepare("UPDATE user_settings (site_name, header_text, footer_copyright, allow_robot_name, default_robot_name) VALUES (?, ?, ?, ?, ?)");
$insert->bind_param('sssss', $site_name, $header_text, $footer_copyright, $allow_robot_name, $default_robot_name);
if ($insert->execute()) {
header('Location: index.php');
die();
}
}
}
}
if ($results = $db->query("SELECT * FROM user_settings")) {
if ($results->num_rows) {
while ($row = $results->fetch_object()) {
$records[] = $row;
}
$results->free();
}
}
?>
This is my db connection code in db_connect.php
:
<?php
require_once('../db_config.php');
$db = new mysqli(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
if ($db->connect_errno) {
die('Sorry, we are currently experiencing some problems.');
}
?>
Does anyone know why I am getting this error?