在准备好的声明的准备部分中有变量的问题

时间:2015-07-24 02:10:44

标签: php mysqli prepared-statement

我正在尝试进行更新查询。让我失望的部分是在准备部分中有变量。我正在尝试获取与我所在页面关联的现有$ cid和$ tid。

$cid = category id
$tid= topic id

我注释掉了绑定参数,因为我已经在页面上定义了变量。

然后我收到此错误:

Fatal error: Call to a member function execute() on a non-object in

如何使这个准备好的语句工作并使它成为一个对象,以便它运行?

$stmt3 = $con->prepare("UPDATE forum_topics SET topic_views='".$new_views."' WHERE category_id'".$cid."' AND id='".$tid."' LIMIT 1");
//$stmt3->bind_param("ii", $cid, $tid);
$stmt3->execute();
$stmt3->store_result();
$row3 = $stmt3->fetch();
    }   else {

附加代码......

$old_views = $row['topic_views'];
$new_views = $old_views + 1;

        //$stmt3 = $con->prepare("UPDATE forum_topics SET topic_views='".$new_views."' WHERE category_id'".$cid."' AND id='".$tid."' LIMIT 1");
            $stmt3 = $con->prepare("UPDATE forum_topics SET `topic_views`=? WHERE `category_id`=? AND `id`=? LIMIT 1");
        $stmt3->bind_param("iii", $new_views, $cid, $tid);
            $stmt3->execute();
            //$stmt3->store_result();
            $row3 = $stmt3->fetch();
    }   else {
        echo "<p>This topic does not exist.</p>";
        }

0 个答案:

没有答案