2016-08-02 38 views
0

我們編輯任何特定用戶記錄時會發生錯誤,然後自動更改所有用戶數據。 我的代碼:在codeigniter中爲特定用戶編輯值

控制器

public function edit($id){ 
    if (isset($_POST) && !empty($_POST)) 
     { 
     if ($this->Home->update($id)) 
      { 
      $this->do_image_upload($id); 
      $this->session->set_flashdata('message ', 'code already exist , please try with different code'); 
      redirect('Welcome/index1'); 
      } 
      else 
      { 
      $this->session->set_flashdata('message ', 'code already exist , please try with different code'); 
      } 
     } 

    $data['client'] = $this->Home->get($id); 
    $this->load->view('edit ', $data); 
    } 

模型

public function update($id) 
    { 
    $id=$_POST['id']; 

     $data = array(
      'invoice' => $this->input->post('invoice'), 
     ); 

      $this->db->where('id', $id); 
      $this->db->update('data', $data); 
      if($this->db->update('data', $data)) 
       { 
        return true; 
       } 
       else 
       { 
        return false; 
       } 

    } 

觀點:

回答

0

請試試這個代碼....

$data = array('invoice' => $this->input->post('invoice')); 
$where= array('id' => $id); 
$this->db->update('data', $data,$where); 
0

請儘量做到以下C在模型中的變更:

public function update($id) 
{ 
$id=$_POST['id']; 

    $data = array(
     'invoice' => $this->input->post('invoice'), 
    ); 

     $this->db->where('id', $id); 
     //$this->db->update('data', $data); remove this line as code will execute same update command twice 
     if($this->db->update('data', $data)) 
      { 
       return true; 
      } 
      else 
      { 
       return false; 
      } 

}