2013-11-27 41 views
1

在我的數據庫我有這樣的:更新查詢到的圖像

<p>Evento de Natal <img alt="" src="http://2.bp.blogspot.com/-kGiurC1ZAYY/TtxsnlfGfOI/AAAAAAAAAZA/A_QbRtqNnJU/s1600/40arvoresnatalmagiagifs.gif" style="float:right; height:199px; width:200px" /></p> 

當我插入這個代碼在DB工作正常。 但是當我嘗試更新具有相同代碼的數據庫以更新函數時,它會給出以下錯誤:http://i.imgur.com/W89z9Hl.png

建議不要直接在數據庫中插入HTML?我怎麼做? 這裏是我的功能插入和更新。

public function insertNew($data) { 
    $this->db->insert('noticias', $data); 
    redirect(site_url('/') . 'admin/'); 
} 
public function updateNew($id, $title, $noticia, $event) { 
    $this->db->query('UPDATE noticias SET title="' . $title . '" , noticia="' . $noticia . '", event="' . $event . '" WHERE id= "' . $id . '"'); 
    redirect(site_url('/') . 'admin/all_news'); 
} 

回答

1

您需要轉義引號。但是,如果你使用內置的笨的insert功能何不也用它update功能:

public function updateNew($id, $title, $noticia, $event) { 
    $data = array(
     'title' => $title, 
     'noticia' => $noticia, 
     'event' => $event 
    ); 

    $this->db->where('id', $id); 
    $this->db->update('noticias', $data); 

    redirect(site_url('/') . 'admin/all_news'); 
} 

Im相當肯定,當它與插入功能的工作原理,笨就會做轉義爲你更新了。

+0

謝謝!我知道了。每天學習一點。 :) – IRONLORD

1

看來$這個 - > DB->插入方法不正確的字符串轉義而你傳遞的原始查詢作爲參數$這個 - > DB->查詢沒有。

您確定$ this-> db不包含更新或替換方法嗎?如果沒有,你應該添加它們。您可以將其基於當前插入方法並根據您的需要進行修改。

+0

哼哼......我明白你的意思了......從未考慮過它。我會更仔細地檢查。 – IRONLORD