2017-06-16 8 views
3

データベース内のデータを更新できません.i何がhappend.pleaseに役立つか分かりません。データを表示する編集ボタンを押します。しかし、データベースのデータは編集できません。私は以下のコードを掲載しているデータベース内のデータを更新できませんCodeigniter

Controller.php

public function ajax_update() 
{ 
    $data = array(
      'placename' => $this->input->post('placename'), 
      'description' => $this->input->post('description'), 
      'tel' => $this->input->post('tel'), 
      'latitude' => $this->input->post('latitude'), 
      'longtitude' => $this->input->post('longtitude'), 
      'placetype_id' => $this->input->post('placetype_id'), 
      'province_id' => $this->input->post('province_id'), 

     ); 
    $this->tblplace->update(array('placeid' => $this->input->post('placeid')), $data); 
    echo json_encode(array("status" => TRUE)); 
} 

Modal.php

public function save($data) 
{ 
    $this->db->insert('tblplace', $data); 
    return $this->db->insert_id(); 
} 

public function update($where, $data) 
{ 
    $this->db->update('tblplace', $data, $where); 
    return $this->db->affected_rows(); 
} 

私は、データベースからのデータがテキストボックスに表示するために取得することができます。しかし、データを更新することはできません。助けが必要です。ありがとうございます。

+0

あなたは 'ajax_update()'メソッドのポストからデータを取得することができますか? –

+0

モデルのWHERE条件はどこですか? – user3663

+0

[保存]ボタンを押すことはできますが、変更データは更新されません。 –

答えて

0

あなたのコントローラー:モデルで

public function ajax_update() 
{ 
    //You should also check the post array. 
    $ajax_post_data = $this->input->post(); 
    log_message('debug', 'Ajax Post Data Array:' . print_r($ajax_post_data, TRUE)); 

    $placeid = $this->input->post('placeid'); 

    $data = array(
      'placename' => $this->input->post('placename'), 
      'description' => $this->input->post('description'), 
      'tel' => $this->input->post('tel'), 
      'latitude' => $this->input->post('latitude'), 
      'longtitude' => $this->input->post('longtitude'), 
      'placetype_id' => $this->input->post('placetype_id'), 
      'province_id' => $this->input->post('province_id'), 

     ); 
    $this->load->model('tblplace'); 
    $updte_status = $this->tblplace->update($placeid, $data); 
    if($updte_status == TRUE){ 
     echo json_encode(array("status" => true)); 
    } else { 
     echo json_encode(array("status" => false)); 
    } 
} 

public function update($where, $data) 
{ 

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

    log_message('debug', 'Last Update Query:' . print_r($this->db->last_query(), TRUE)); 
    log_message('debug', 'Affected row count:' . print_r(count($this->db->affected_rows()), TRUE)); 
    if ($this->db->affected_rows() === 1) { 
     return TRUE; 
    }else{ 
     return FALSE; 
    } 
} 

希望これは明らかであり、それはあなたがデータを更新するのに役立ちます。

0

where条件は、あなたの更新機能ではありません

public function update($where, $data) 
    { 
     $this->db->where($where); 
     $this->db->update('tblplace', $data); 
     return $this->db->affected_rows(); 
    } 
関連する問題