在codeigniter中为特定用户编辑值

时间:2016-08-02 09:51:47

标签: php codeigniter-3

当我们编辑任何特定用户记录然后自动更改所有用户数据时,我发生错误。 我的代码:

控制器

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

    }

视图:

2 个答案:

答案 0 :(得分:0)

请尝试此代码....

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

答案 1 :(得分: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;
          }

}
相关问题