title: The proper way to insert a NULL into a database with CodeIgniter
body: <p>I have ExtJS post data from a combofield to CodeIgniter. CodeIgniter reads the posted data and runs db->insert to update the mssql database.</p>
  
  <p>The problem is if the user doesn't choose a selection from the combobox it is sent to CodeIgniter as nothing, Codeignighter then reads this piece of posted data as an empty string and attempts to write that to the int field in the database causing an error.</p>
  
  <p>I believe I need CodeIgniter to treat the string as NULL if it's empty and a number if it is such. I have tried using php type juggling (int) to convert it but it makes it a 0. This is an invalid value because it doesn't match any selection in my one to many int field in my DB.</p>
  
  <p>Is there a way to make CodeIgniter treat empty strings as NULLS instead of empty strings?</p>
  
  <p>[EDITED TO ADD CODE]</p>
  
  <pre><code>{
  //ExtJS combo object
  xtype: 'combo',
  id: 'Referrer',
  store: new Ext.data.Store({
      proxy: new Ext.data.HttpProxy({
          url: '/referrals/index.php/referrers/read',
          method: 'POST'
      }),
      reader: new Ext.data.JsonReader({
          root: 'results',
          fields: [
              {name: 'ID'},
              {name: 'Referrer'}
          ]
      })
  }),
  displayField: 'Referrer',
  valueField: 'ID',
  value: 1,
  typeAhead: true,
  hiddenName: 'Referrers_ID',
  mode: 'remote',
  triggerAction: 'all',
  fieldLabel: 'Referrer',
  selectOnFocus: true,
  anchor: '100%'
  }
  
  //CI CODE TO GRAB FROM POST INTO AN ARRAY THEN OUT TO THE DB
  public function create(){
      $data = array(  
          'FirstName' =&gt; $this-&gt;input-&gt;post('FirstName', false),
          'LastName' =&gt; $this-&gt;input-&gt;post('LastName', false),
          'DOB' =&gt; $this-&gt;input-&gt;post('DOB', false),
          'Email' =&gt; $this-&gt;input-&gt;post('Email', false),
          'Phone' =&gt; $this-&gt;input-&gt;post('Phone', false),
          'StudentNo' =&gt; $this-&gt;input-&gt;post('StudentNo', false),
          'Sex' =&gt; $this-&gt;input-&gt;post('Sex', false),
          'Advisors_ID' =&gt; $this-&gt;input-&gt;post('Advisors_ID', false),
          'DateSeen' =&gt; $this-&gt;input-&gt;post('DateSeen', false),
          'Classifications_ID' =&gt; join(",", $this-&gt;input-&gt;post('Classifications_ID', false)),
          'Referrers_ID' =&gt; $this-&gt;input-&gt;post('Referrers_ID', false),
          'Referrals' =&gt; $this-&gt;input-&gt;post('Referrals', false),
          'ReferralNotes' =&gt; $this-&gt;input-&gt;post('ReferralNotes', false),
          'Registration1' =&gt; $this-&gt;input-&gt;post('Registration1', false),
          'Registration2' =&gt; $this-&gt;input-&gt;post('Registration2', false),
          'Notes' =&gt; $this-&gt;input-&gt;post('Notes', false)
      );
  
      $this-&gt;db-&gt;insert('Clients', $data);
      $insert_id = $this-&gt;db-&gt;insert_id();
  }
  </code></pre>