我正在製作一個類的遊戲,我有一個用戶設置頁面,管理員可以在其中修改設置。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'關鍵字。 –