2017-02-15 172 views
0

我試圖與此代碼更新SQL數據庫PDO

public function updateImprovement($id, $improveId, $body) { 

    //UPDATE ITC 
    $update = ("UPDATE as_improvement SET value = :value WHERE id = :id"); 

    $statement = $this->db-> prepare($update); 

    $statement -> bindValue(":id", $id, PDO::PARAM_STR); 
    $statement -> bindValue(":value", $body, PDO::PARAM_STR); 


    $statement -> execute(); 

    //UPDATE IMPROVE 
    $update = ("UPDATE as_improve SET content_new = :content_new AND approved = 1 WHERE id = :improveId"); 

    $statement = $this->db-> prepare($update); 


    $statement -> bindValue(":improveId", $improveId, PDO::PARAM_STR); 
    $statement -> bindValue(":content_new", $body, PDO::PARAM_STR); 



    $statement -> execute(); 

} 

的問題是在「content_new」更新一些數據庫值 - >(content_new =:content_new)變量,因爲沒有它,SQL句子完美執行。我可以在兩個句子中使用$ body兩次嗎?

+0

不應該在查詢Seconde系列是這樣? 'UPDATE as_improve SET content_new =:content_new,approved = 1 WHERE id =:improveId' –

+1

哦,男人,一定是完全錯過了。感謝您的幫助,它現在可行! :) – SaTTko

+2

這裏的jQuery在哪裏? – empiric

回答

0

你正在運行content_new = :content_new AND approved = 1

它應該是:content_new = :content_new, approved = 1

不過,我已經重新吉格舞這一點對你:

public function updateImprovement($id, $improveId, $body) { 

    //UPDATE ITC 
    $update = ("UPDATE as_improvement SET value = ? WHERE id = ?"); 
    $statement = $this->db-> prepare($update); 
    $statement->execute([$body, $id]); 

    //UPDATE IMPROVE 
    $update = ("UPDATE as_improve SET content_new = ?, approved = 1 WHERE id = ?"); 
    $statement = $this->db-> prepare($update); 
    $statement->execute([$body, $improveId]); 
}