title: Inserting data into database using if statement
body: <p>I wrote a code to insert input data to database using codeigniter but before inserting, data will go through an if statement to check the input then if condition is met data will be saved. </p>
  
  <p>I was trying to check if the input data is equal to section then parent id must be 0. Else if not section then the $data['type'] entered must be inserted to database and parent id must not be 0.
  This is my code so far.</p>
  
  <pre><code>$data = array (
  'title' =&gt; $this-&gt;input-&gt;post-&gt;('title'),
  'type' =&gt; $this-&gt;input-&gt;post-&gt;('type'),
  'description' =&gt; $this-&gt;input-&gt;post-&gt;('description')
  ); 
  
  
  if ($data['type'] == 'section') {
           $data['parent_id'] = 0;
         } else {
           $data['parent_id']  = $this-&gt;input-&gt;post('parent_id');
           $data['type']  = $this-&gt;input-&gt;post('type');
         }
   $result = $this-&gt;checklist_item_model-&gt;put_item($data);
  </code></pre>
  
  <p>Model</p>
  
  <pre><code>public function put_item ($data) {
     $this-&gt;db-&gt;insert('items', $data);
   }
  </code></pre>