2013-04-12 130 views
0

我試圖運行此代碼在我的「問題」表中插入新行:PHP的PDO插入查詢錯誤

$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

OPTION是保留關鍵字。如果你不想收到任何語法錯誤,你需要使用反引號來逃避它,

INSERT INTO questions (id, quiz_id, question, image, type, 
         `option`, answer, explanation, date) 
VALUES(...)