我正在制作一个类的游戏,我有一个用户设置页面,管理员可以在其中修改设置。SQL更新 - 调用一个非对象的成员函数bind_param()
当我点击更新按钮,我与此错误返回:
Call to a member function bind_param() on a non-object
这是我认为错误是源于代码:
<?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();
}
}
?>
这是我的数据库连接代码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.');
}
?>
有没有人知道为什么我得到这个错误?
因为'$ insert'不是一个声明,这是你的所有代码吗?你的数据库连接在哪里跳过来发布,或者你没有连接到数据库? –
[参考 - 这个错误在PHP中意味着什么?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Anonymous
这种类型的'UPDATE'语法甚至存在?从来没有见过它......看起来更像是插入到我,除了'UPDATE'关键字。 –