不允许我插入带有 where 子句的值


not letting me insert values with a where clause

我正在制作论坛,我正在尝试这样做,以便当您回复主题时,它会将回复信息放在表中(有效),然后将值插入子类别表中,其中子类别 ID 等于此子类别 ID。

法典:

        $query = "INSERT INTO subcategories (last_topic_title, last_topic_date, last_topic_user) VALUES (:last_topic_title, :last_topic_date, :last_topic_user) WHERE cid='".$cid."' AND sid='".$sid."'";
        $query_params = array(':last_topic_title' => $topic_title, ':last_topic_date' => $reply_date, ':last_topic_user' => $reply_creator);
        try {
            $stmt = $db->prepare($query);
            $result = $stmt->execute($query_params);
        }
        catch(PDOException $ex) {
            die("Failed to run query" . $ex->getMessage());
        }

问题:

它不允许我插入带有 WHERE 子句的值。我怎样才能克服这个?

你不能

,因为INSERT语句没有WHERE子句。您需要使用 UPDATE 语句。

有关这两个独立且不同的功能的详细信息,请参阅:

  • http://dev.mysql.com/doc/en/insert.html
  • http://dev.mysql.com/doc/refman/5.0/en/update.html