title: Insert session userdata into a new database in CodeIgniter
body: <p>How would I go about inserting the session userdate <code>id</code> into my new table using the form I have in my view so that I may use the <code>id</code> as a foreign key?</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>function validate_credentials() {
      $this-&gt;load-&gt;model('member_model');
      $query = $this-&gt;member_model-&gt;validate();
      if ($query) { // if user credentials validate the user session start
          $data = array(
              'username' =&gt; $query-&gt;username,
              'id' =&gt; $query-&gt;id,
              'first_name'=&gt;$query-&gt;first_name,
              'is_logged_in' =&gt; true
          );
  
          $this-&gt;session-&gt;set_userdata($data);
  
          redirect('members/members_area');
      } else {
          $this-&gt;index();
          echo 'Incorrect Password or Username';
      }
  }
  </code></pre>
  
  <p><strong>View:</strong></p>
  
  <pre><code>echo form_open('banks/create_bank');
  echo form_input('bank_name', set_value('bank_name', 'Account Name'));
  echo form_input('interest', set_value('interest', 'Interest'));
  echo form_input('start_amount', set_value('start_amount', 'Starting Balance'));
  echo form_input('length', set_value('length', 'Length'));
  echo form_submit('submit', 'Create Account')
  echo validation_errors('&lt;p class="error"/&gt;'); 
  </code></pre>