title: Codeigniter set_value
body: <p>How do I make it so that when I go through with error validation on my post form, it doesn't only send back the default values from the database, but if I were to edit the values and hit submit, it would save the data I tried to update with. I'm stuck where I can only do one or the other.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> 
  &lt;? if (isset($update)) { ?&gt;
  &lt;?php echo set_value ('fname'); ?&gt;
  &lt;?= form_open("Phonebook/updateentry/" . $entry['id']) ?&gt;
  &lt;?= form_fieldset("Update Entry"); ?&gt;
  &lt;?= form_label('First Name: ', 'fname'); ?&gt; &lt;br&gt;
  &lt;?= form_input(array('name' =&gt; 'fname', 'id' =&gt; 'fname', 'value' =&gt;  $entry['fname'])); ?&gt; &lt;br&gt; 
  
  &lt;?= form_label('Last Name: ', 'lname'); ?&gt; &lt;br&gt;
  &lt;?= form_input(array('name' =&gt; 'lname', 'id' =&gt; 'lname', 'value' =&gt; $entry['lname'])); ?&gt; &lt;br&gt;
  &lt;?= form_label('Phone Number: ', 'phone'); ?&gt; &lt;br&gt;
  &lt;?= form_input(array('name' =&gt; 'phone', 'id' =&gt; 'phone', 'value' =&gt; $entry['phone'])); ?&gt; &lt;br&gt;
  &lt;?= form_label('Email: ', 'email'); ?&gt; &lt;br&gt;
  &lt;?= form_input(array('name' =&gt; 'email', 'id'=&gt;'email', 'value' =&gt; $entry['email'])); ?&gt; &lt;br&gt;
  &lt;?= form_submit('phonebooksubmit', 'Submit'); ?&gt;
  &lt;?= form_fieldset_close(); ?&gt;
  &lt;?= form_close() ?&gt;
  &lt;? } ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>private function display()
   {
    $query = $this-&gt;db-&gt;query("SELECT * FROM phonebook ORDER BY id ASC;");
    $this-&gt;TPL['listing'] = $query-&gt;result_array();
    
    $this-&gt;load-&gt;view('phonebook_view', $this-&gt;TPL);
   }
    
     public function updateentry($id)
   {
  
    $this-&gt;form_validation-&gt;set_rules('fname', 'First Name', 'required|alpha|min_length[5]|max_length[15]',
    array(
     'required' =&gt; 'You have not provided the %s. ',
     'alpha' =&gt; '%s must only compose of alphanumeric letters.',
     'max_length' =&gt; 'You exceeded max char of 20 . ',
     'min_length' =&gt; 'The min length must be 5 . '
  
    ));
    $this-&gt;form_validation-&gt;set_rules('lname', 'Last Name', 'required|alpha|min_length[5]|max_length[20]',
    array(
     'required' =&gt; 'You have not provided %s .',
     'alpha' =&gt; '%s must only compose of alphanumeric letters.',
  
     'max_length' =&gt; 'You exceeded max char of 20 . ',
     'min_length' =&gt; 'The min length must be 5 . '
    ));
    $this-&gt;form_validation-&gt;set_rules('phone', 'Phone Number', 'required|regex_match[/^([0-9]{3})[-. ]([0-9]{4})$/]',
    array(
     'required' =&gt; 'You have not provided %s .',
     'regex_match' =&gt; 'Please use the correct phone format.'
    ));
    $this-&gt;form_validation-&gt;set_rules('email', 'Email', 'required|valid_email',
    array(
     'required' =&gt; 'You have not provided %s .',
     'valid_email' =&gt; 'Please provide valid email. '
    ));
    $this-&gt;form_validation-&gt;set_error_delimiters('&lt;p class = "errorlist"&gt;' , '&lt;/p&gt;');
    if ($this-&gt;form_validation-&gt;run() == FALSE) {
     
     $query = $this-&gt;db-&gt;query("SELECT * FROM phonebook where id = '$id';");
     $this-&gt;TPL['entry'] = $query-&gt;result_array()[0];
  
     
     $this-&gt;TPL['update'] = true;
     $this-&gt;TPL['memory'] = true;
   
     $this-&gt;display();
    }
    else
    { 
    
    $fname = $this-&gt;input-&gt;post("fname");
        $lname = $this-&gt;input-&gt;post("lname");
         $phone = $this-&gt;input-&gt;post("phone");
         $email = $this-&gt;input-&gt;post("email");      
         $query = $this-&gt;db-&gt;query("UPDATE phonebook " .
                                "SET fname = '$fname'," .
                                "    lname = '$lname'," .
                                "    phone = '$phone'," .
                                "    email = '$email'" .
                                " WHERE id = '$id';");  
    $this-&gt;display();
   }
  }
    </code></pre>
  </div>
  </div>
  </p>
  
  <p>I know I have to use the set_value() but i'm not sure how to make it so that it can do both.</p>