title: Codeigniter Model Undefined Index on Array
body: <p>I'm trying to use Codeigniter to update my value once the user had submitted the form. But unfortunately, there was an error of undefined index for few of the variable which I store in an array.</p>
  
  <p>Below is the Code that I use to pass from Controller to the Model</p>
  
  <p>Controller Code :</p>
  
  <pre><code>$prep_data = array(
                  'full_name' =&gt; $this-&gt;input-&gt;post('full_name'),
                  'nric' =&gt; $this-&gt;input-&gt;post('nric'),
                  'dob' =&gt; $this-&gt;input-&gt;post('dob'),
                  'mobile_phone' =&gt; $this-&gt;input-&gt;post('mobile_phone'),
                  'email' =&gt; $this-&gt;input-&gt;post('email'),
                  'address_line_1' =&gt; $this-&gt;input-&gt;post('address_line_1'),
                  'address_line_2' =&gt; $this-&gt;input-&gt;post('address_line_2'),
                  'postcode' =&gt; $this-&gt;input-&gt;post('postcode'),
                  'state' =&gt; $this-&gt;input-&gt;post('state'),
                  'current_brand' =&gt; $this-&gt;input-&gt;post('current_brand'),
                  'pregnant' =&gt; $isPregnant, //Edit by Marcus
                  'breastfeeding' =&gt; $isBreastfeeding, //Added by Marcus
                  'child_full_name' =&gt; $this-&gt;input-&gt;post('child_full_name'),
                  'child_dob' =&gt; $this-&gt;input-&gt;post('child_dob'),
                  'child_current_brand' =&gt; $this-&gt;input-&gt;post('child_current_brand'),
                  'expected_give_birth_date' =&gt; $this-&gt;input-&gt;post('expected_give_birth_date'),
                  'image' =&gt; '',
                  'quantity_purchase' =&gt; $this-&gt;input-&gt;post('quantity_purchase'),
                  'foc_amount' =&gt; $this-&gt;input-&gt;post('foc_amount'),
                  'marketing_opt' =&gt; $this-&gt;input-&gt;post('marketing_opt'),
                  'centre_id' =&gt; get_cookie('abbott_centre', TRUE),
                  'user_id' =&gt; $this-&gt;session-&gt;id,
                  'sampling_day' =&gt; $centre_data['sampling_day'],
                  'created_at' =&gt; $datetime,
                  'updated_at' =&gt; $datetime
              );
  $this-&gt;entry_model-&gt;update_entry($prep_data);
  </code></pre>
  
  <p>Model Code : </p>
  
  <pre><code>   function update_entry($data){
          echo print_r($data);
          if(!empty($data['full_name'])) $this-&gt;db-&gt;set('full_name', $data['full_name']);
          if(!empty($data['nric'])) $this-&gt;db-&gt;set('nric', $data['nric']);
          if(!empty($data['dob'])) $this-&gt;db-&gt;set('dob', $data['dob']);
          if(!empty($data['mobile_phone'])) $this-&gt;db-&gt;set('mobile_phone', $data['mobile_phone']);
          if(!empty($data['email'])) $this-&gt;db-&gt;set('email', $data['email']);
          if(!empty($data['address_line_1'])) $this-&gt;db-&gt;set('address_line_1', $data['address_line_1']);
          if(!empty($data['address_line_2'])) $this-&gt;db-&gt;set('address_line_2', $data['address_line_2']);
          if(!empty($data['postcode'])) $this-&gt;db-&gt;set('postcode', $data['postcode']);
          if(!empty($data['state'])) $this-&gt;db-&gt;set('state', $data['state']);
          if(!empty($data['current_brand'])) $this-&gt;db-&gt;set('current_brand', $data['current_brand']);
          if(!empty($data['pregnant'])){ //Fix by Marcus
              $this-&gt;db-&gt;set('pregnant', $data['pregnant']);
          }else {
              $this-&gt;db-&gt;set('pregnant', 0);
          }
          if(!empty($data['breastfeeding'])){ //Fix by Marcus
              $this-&gt;db-&gt;set('breastfeeding', $data['breastfeeding']);
          }
          else {
              $this-&gt;db-&gt;set('breastfeeding', 0);
          }
          if(!empty($data['expected_give_birth_date'])) $this-&gt;db-&gt;set('expected_give_birth_date', $data['expected_give_birth_date']);//Fix by Marcus
          if(!empty($data['child_full_name'])) $this-&gt;db-&gt;set('child_full_name', $data['child_full_name']);
          if(!empty($data['child_dob'])) $this-&gt;db-&gt;set('child_dob', $data['child_dob']);
          if(!empty($data['child_current_brand'])) $this-&gt;db-&gt;set('child_current_brand', $data['child_current_brand']);
          if(!empty($data['image'])) $this-&gt;db-&gt;set('image', $data['image']);
          if(isset($data['quantity_purchase'])) $this-&gt;db-&gt;set('quantity_purchase', $data['quantity_purchase']);
          if(isset($data['foc_amount'])) $this-&gt;db-&gt;set('foc_amount', $data['foc_amount']);
          if(!empty($data['marketing_opt'])) $this-&gt;db-&gt;set('marketing_opt', $data['marketing_opt']);
          if(!empty($data['centre_id'])) $this-&gt;db-&gt;set('centre_id', $data['centre_id']);
          if(!empty($data['user_id'])) $this-&gt;db-&gt;set('user_id', $data['user_id']);
          if(!empty($data['created_at'])) $this-&gt;db-&gt;set('created_at', $data['created_at']);
          if(!empty($data['updated_at'])) $this-&gt;db-&gt;set('updated_at', $data['updated_at']);
  
          $this-&gt;db-&gt;where('id', $data['id']);
          $this-&gt;db-&gt;update('entry');
      }
  </code></pre>
  
  <p>Other $data[] value had no problem but only the 'pregnant' and 'breastfeeding' had the error on Undefined Index. I did try to print_r to show the $data value and all are seem to be alright.</p>
  
  <p>Below are the output : </p>
  
  <pre><code>Array ( [full_name] =&gt; e2e [nric] =&gt; 123 [dob] =&gt; 2019-07-09 [mobile_phone] =&gt; 1231231231 [email] =&gt; [address_line_1] =&gt; [address_line_2] =&gt; [postcode] =&gt; [state] =&gt; [current_brand] =&gt; [pregnant] =&gt; 0 [breastfeeding] =&gt; 1 [child_full_name] =&gt; [child_dob] =&gt; 0000-00-00 [child_current_brand] =&gt; [expected_give_birth_date] =&gt; 2019-07-09 [image] =&gt; [quantity_purchase] =&gt; 123123 [foc_amount] =&gt; 123 [sampling_day] =&gt; [updated_at] =&gt; 2019-07-10 19:27:43 [id] =&gt; 8 ) 1Array ( [image] =&gt; 8_20190710_192743.jpg [id] =&gt; 8 ) 1
  </code></pre>
  
  <p>What will be the caused for this 'pregnant' and 'breastfeeding' array? As it keeps getting NULL as a return.</p>
  
  <p>Thanks</p>