2012-11-29 74 views
0

我得到這個錯誤:MySQL錯誤:無效的參數號

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /FondManager.class.php on line 69 

當試圖執行此:

$Fond_Modif = $Manager->get($id); 
$Fond_Modif->setContactname($_POST['name']); 
$Manager->update($Fond_Modif); 

這裏是關注類:

public function update(Fond $Fond) 
    { 
    $q = $this->_db->prepare('UPDATE fonds SET Name, ContactName, ContactPosition, ContactMail, ContactPhone, Website, MinTic, MaxTic WHERE id = :id'); 

    $q->bindValue(':id', $Fond->id()); 
    $q->bindValue(':name', $Fond->name(), PDO::PARAM_INT); 
    $q->bindValue(':contactname', $Fond->contactname(), PDO::PARAM_INT); 
    $q->bindValue(':contactposition', $Fond->contactposition(), PDO::PARAM_INT); 
    $q->bindValue(':contactmail', $Fond->contactmail(), PDO::PARAM_INT); 
    $q->bindValue(':contactphone', $Fond->contactphone(), PDO::PARAM_INT); 
    $q->bindValue(':website', $Fond->website(), PDO::PARAM_INT); 
    $q->bindValue(':mintic', $Fond->mintic(), PDO::PARAM_INT); 
    $q->bindValue(':maxtic', $Fond->maxtic(), PDO::PARAM_INT); 

    $q->execute(); 
    } 

回答

7

你必須在您的查詢中「提及」所有佔位符

$q = $this->_db->prepare("UPDATE fonds 
          SET Name = :name, 
          ContactName = :contactname, 
          ContactPosition = :contactposition, 
          ContactMail = :contactmail, 
          ContactPhone = :contactphone, 
          Website = :website 
          MinTic = :mintic, 
          MaxTic = :maxtic 
          WHERE id = :id"); 

PDO僅替換佔位符。您必須將該佔位符添加到您的查詢中。

+0

警告:PDOStatement :: execute()[pdostatement.execute]:SQLSTATE [42000]:語法錯誤或訪問衝突:1064您的SQL語法錯誤;檢查與您的MySQL服務器版本對應的手冊,以便在/Applications/XAMPP/xamppfiles/htdocs/JG/FondManager.class.php的第8行'MinTic ='2',MaxTic ='500''附近使用正確的語法在線79 複製你的代碼,現在我得到這個錯誤:) –

+0

他們不在你的查詢。只有列名。並且你也缺少'=' –

+0

非常感謝!我忘記了一些逗號! –