title: Codeigniter - Can't update data in MySQL Database
body: <p>I have some problem with CodeIgniter, I can't update data in a record in CodeIgniter. 'id_user' is the primary key of my user table. I have tried to solve this problem but I couldn't. I hope someone can help with this problem. Thanks a lot :)</p>
  
  <p>I have posted the code below :</p>
  
  <p>HTML5 code :</p>
  
  <pre><code>&lt;form action="&lt;?php echo base_url(). 'crud/update'; ?&gt;" method="post"&gt;
      &lt;input name="id_user" type="text" class="form-control" value="&lt;?php echo $id_usernya ?&gt;"&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;Alamat :&lt;/label&gt;
          &lt;textarea name="alamat_user" class="form-control" rows="5" placeholder="Alamat" &gt;&lt;?php echo $usernya-&gt;alamat_user ?&gt;&lt;/textarea&gt;
      &lt;/div&gt; 
      &lt;div class="form-group"&gt;
          &lt;input name="kodepos_user" type="text" class="form-control" value="&lt;?php echo $usernya-&gt;kodepos_user ?&gt;"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;input type="hidden" name="provinsi_user"&gt;
          &lt;select name="provinsi_id_user" class="form-control"&gt;
              &lt;option value=""&gt;Pilih Provinsi&lt;/option&gt;
              &lt;option selected value="&lt;?php echo $usernya-&gt;provinsi_user ?&gt;"&gt;&lt;?php echo $usernya-&gt;provinsi_user ?&gt;&lt;/option&gt;
              &lt;?php echo $provinsi ?&gt;
          &lt;/select&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;input type="hidden" name="kota_user"&gt;
          &lt;select name="kota_id_user" class="form-control"&gt;
              &lt;option value=""&gt;Pilih Kota&lt;/option&gt;
              &lt;option selected value="&lt;?php echo $usernya-&gt;kota_user ?&gt;"&gt;&lt;?php echo $usernya-&gt;kota_user ?&gt;&lt;/option&gt;
          &lt;/select&gt;
      &lt;/div&gt;
      &lt;input type="submit" class="btn btn-primary" value="Simpan"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Controller :</p>
  
  <pre><code>class Crud extends CI_Controller{
  
  function __construct(){
      parent::__construct();      
      $this-&gt;load-&gt;model('m_data');
      $this-&gt;load-&gt;helper('url');
  
  }
  
  function edit($id_user){
          $where = array('id_user' =&gt; $id_user);
          $data['user'] = $this-&gt;m_data-&gt;edit_data($where,'user')-&gt;result();
          $this-&gt;load-&gt;view('back/user/v_beranda',$data);
          redirect('beranda/index');
      }
  
      function update(){
      $id_user = $this-&gt;input-&gt;post('id_user');
      $alamat_user = $this-&gt;input-&gt;post('alamat_user');
      $kodepos_user = $this-&gt;input-&gt;post('kodepos_user');
      $provinsi_id_user = $this-&gt;input-&gt;post('provinsi_id_user');
      $kota_id_user = $this-&gt;input-&gt;post('kota_id_user');
  
      $data = array(
          'alamat_user' =&gt; $alamat_user,
          'kodepos_user' =&gt; $kodepos_user,
          'provinsi_id_user' =&gt; $provinsi_id_user,
          'kota_id_user' =&gt; $kota_id_user
      );
  
      $where = array(
          'id_user' =&gt; $id_user
      );
  
      $this-&gt;m_data-&gt;update_data($where,$data,'user');
      redirect('beranda/index');
  }
  </code></pre>
  
  <p>Model code :</p>
  
  <pre><code>&lt;?php 
  
  class M_data extends CI_Model{
  
      function edit_data($where,$table){      
          return $this-&gt;db-&gt;get_where($table,$where);
      }
  
      function update_data($where,$data,$table){
          $this-&gt;db-&gt;where($where);
          $this-&gt;db-&gt;update($table,$data);
      }   
  }
  </code></pre>