title: Error when checking if a cookie is set
body: <p>I am using this in my controller to check if a cookie was already set. If not, I set it.</p>
  
  <pre><code>function x(){
      if(!isset($_COOKIE['sg'])){
          $this-&gt;load-&gt;model('generate_model');
          $val=$this-&gt;generate_model-&gt;random();
          setcookie('sg',$val, time()+3600*24*30*12*3,"/", "" );
      }
      $this-&gt;load-&gt;model('model');
      $data['cod']=$cod;
      $this-&gt;model-&gt;select($cod);
      $this-&gt;load-&gt;view('templates/header');
      redirect('Home','refresh');
  }
  </code></pre>
  
  <p>If the cookie was not set, I get two errors:</p>
  
  <blockquote>
    <p>A PHP Error was encountered</p>
    
    <p>Severity: Notice</p>
    
    <p>Message: Undefined index: sg</p>
    
    <p>Filename: models/select_gift_model.php</p>
    
    <p>Line Number: 12</p>
    
    <p>A Database Error Occurred</p>
    
    <p>Error Number: 1048</p>
    
    <p>Column 'uid' cannot be null</p>
    
    <p>INSERT INTO <code>id</code> ( <code>uid</code>, <code>cod</code>) VALUES ( NULL, '35A5V0Mogc')</p>
    
    <p>Filename: C:\wamp\www\ci\system\database\DB_driver.php</p>
    
    <p>Line Number: 330</p>
  </blockquote>
  
  <p>The cookie is set, and if I press back and call again, the function works normally.</p>
  
  <p>How can I check if a cookie is set and make the function work properly?</p>