title: how to update form data in codeigniter
body: <p>I am new in codeigniter.</p>
  <p>I am using codeigniter for this project. I have not getting how to update form data in the database. I have inserting,showing data in the databse is done. But I cant understand, how to update data in the database.</p>
  <p>My controller:</p>
  <pre><code>    class User extends CI_Controller {
  
          public function __construct() {
              // Call the Model constructor
              parent::__construct();
              $this-&gt;load-&gt;model('usermodel');
          }
  
          public function insert() {
              $this-&gt;load-&gt;view('userview');
  
              if ($this-&gt;input-&gt;post('submit')) {
  
                  $this-&gt;usermodel-&gt;save();
              }
          }
  
          public function display() {
              $data = array();
              $data['result'] = $this-&gt;usermodel-&gt;get_contents();
              $this-&gt;load-&gt;view('usergrid', $data);
          }
  
          public function edit() {
              $data = array();
              $get = $this-&gt;uri-&gt;uri_to_assoc();
              $data['result'] = $this-&gt;usermodel-&gt;entry_update( $get['id'] );
  
              $this-&gt;load-&gt;view('useredit', $data);
               if ($this-&gt;input-&gt;post('submit')) {
  
                  $this-&gt;usermodel-&gt;entry_update1($get['id']);
              }
          }
  
  
      }
  </code></pre>
  <p>model:</p>
  <pre><code>        &lt;?php
  
          class Usermodel extends CI_Model {
  
              public function __construct() {
                  // Call the Model constructor
                  parent::__construct();
              }
  
              public function save() {
  
                  //print_r($this-&gt;input-&gt;post('name'));
  
                  $data = array(
                      'name' =&gt; $this-&gt;input-&gt;post('name'),
                      'age' =&gt; $this-&gt;input-&gt;post('age'),
                      'address' =&gt; $this-&gt;input-&gt;post('address')
                  );
                  //var_dump($this-&gt;db);
  
                  $this-&gt;db-&gt;insert('user', $data);
              }
  
              public function get_contents() {
                  $this-&gt;db-&gt;select('*');
                  $this-&gt;db-&gt;from('user');
                  $query = $this-&gt;db-&gt;get();
                  return $result = $query-&gt;result();
              }
  
  
              public function entry_update( $id ) {
  
                  $this-&gt;db-&gt;select('*');
                  $this-&gt;db-&gt;from('user');
                  $this-&gt;db-&gt;where('id',$id );
                  $query = $this-&gt;db-&gt;get();
                  return $result = $query-&gt;row_array();
  
              }
              public function entry_update1($id) {
                $data = array(
         
          'name' =&gt; $this-&gt;input-&gt;post('name'),
          'age' =&gt; $this-&gt;input-&gt;post('age'),
          'address' =&gt; $this-&gt;input-&gt;post('address')
                  );
  
                   $this-&gt;db-&gt;where('id', $id);
                  $this-&gt;db-&gt;update('user', $data);
  
              }
  
          }
          ?&gt;
  </code></pre>
  <p>view:</p>
  <pre><code>    &lt;html&gt;
          &lt;head&gt;
              &lt;title&gt;user registration&lt;/title&gt;
          &lt;/head&gt;
          &lt;body&gt;
              &lt;form  action=&quot;edit&quot;  method=&quot;POST&quot; name=&quot;myform&quot;&gt;
                  &lt;input type=&quot;hidden&quot; name=&quot;id&quot; value=&quot;&lt;?php echo $result['id']; ?&gt;&quot;&gt;
                  username :&lt;input type=&quot;text&quot; name=&quot;name&quot; value=&quot;&lt;?php echo $result['name'] ?&gt;&quot;&gt;&lt;/br&gt;
                  age      :&lt;input type=&quot;text&quot; name=&quot;age&quot; value=&quot;&lt;?php echo $result['age'] ?&gt;&quot;&gt;&lt;/br&gt;
                  Address  :&lt;input type=&quot;text&quot; name=&quot;address&quot; value=&quot;&lt;?php echo $result['address'] ?&gt;&quot;&gt;&lt;/br&gt;
  
                  &lt;input type=&quot;submit&quot; value=&quot;update&quot; name=&quot;submit&quot;&gt;
              &lt;/form&gt;
          &lt;/body&gt;
  
      &lt;/html&gt;
  </code></pre>
  <p>Thank you in advance for your help.</p>