2016-08-02 3 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

다음과 같이 해보세요 기음 모델에 교수형 :

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; 
      } 

}