我正在为课堂制作一个游戏,我已经添加了一个评论系统来配合它。我现在想增加报告评论的能力。
我在comments表中添加了一个名为report_active的列,我的想法是在它处于活动状态时将其设置为1(这意味着它已经被报告了),而当它不是的时候设置为0。然后在adminCP中列出所有的注释,并在其中包含一个活动的报告。
我创建了一个名为report_comment.php的文件,我打算只用于运行查询,然后重定向回另一个页面。
这是我的report_comment.php页面:
<?php
require_once('db_connect.php');
require_once('security.php');
if (isset($_GET['id'])) {
$report_active = 1;
$id = $_GET['id'];
$select = $db->query("SELECT * FROM comments WHERE id = ?");
$select->bind_param('i', $id);
if ($select->execute()) {
if ($select->num_rows) {
// Run the update query
$update = $db->query("UPDATE comments SET report_active = ? WHERE id = ?");
$update->bind_param('ii', $report_active, $id);
if ($update->execute()) {
header('Location: comments.php');
die();
}
}
}
}
?>我做错了什么?因为这是我返回的错误:
Fatal error: Call to a member function bind_param() on a non-object
发布于 2014-04-16 20:18:17
$select = $db->query("SELECT * FROM comments WHERE id = ?");
^^^^^---execute the query immediately你想要的
$stmt = $db->prepare("SELECT * FROM comment WHERE id = ?");
^^^^^^^---note the diff而不是。另外,你应该检查失败。
if ($stmt === false) {
die("Prepare failed with error: " . $db->errorInfo);
}或类似于您的特定DB库。
https://stackoverflow.com/questions/23119281
复制相似问题