0

我正在尝试运行此代码以在“问题”表中插入新行:

$sql = "INSERT INTO questions (id,quiz_id,question,image,type,option,answer,explanation,date) 
        VALUES (:id, :quiz_id, :question, :imagesstring, :type, :optionsstring, :answer, :explanation, :date)";
$query = $db->prepare($sql);
$results = $query->execute(array(
    ":id" => $id,
    ":quiz_id" => $quiz_id,
    ":question" => $question,
    ":imagesstring" => $imagesstring,
    ":type" => $type,
    ":optionsstring" => $optionsstring,
    ":answer" => $answer,
    ":explanation" => $explanation,
    ":date" => $date 
));

它说附近有语法错误,但我找不到。我多次检查表格,列与我插入的变量相对应。变量也具有分配给它们的正确值。请帮忙。

4

1 回答 1

4

OPTION是保留关键字。如果您不想收到任何语法错误,则需要使用反引号将其转义,

INSERT INTO questions (id, quiz_id, question, image, type, 
                       `option`, answer, explanation, date)
VALUES(...)
于 2013-04-12T02:58:25.750 回答