title: Message: Undefined variable: data - CodeIgniter
body: <p>Hi guys I have this code and I am not sure what I am doing wrong, data is being defined as far as I can see, these are the errors I am getting:</p>
  
  <pre><code>A PHP Error was encountered
  
  Severity: Notice
  
  Message: Undefined variable: data
  
  Filename: models/site_model.php
  
  Line Number: 14
  A PHP Error was encountered
  
  Severity: Warning
  
  Message: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/BLOCK/system/core/Exceptions.php:185)
  
  Filename: core/Common.php
  
  Line Number: 442
  A Database Error Occurred
  
  You must use the "set" method to update an entry.
  
  Filename: /Applications/XAMPP/xamppfiles/htdocs/BLOCK/models/site_model.php
  
  Line Number: 14
  </code></pre>
  
  <p>controller:</p>
  
  <pre><code>&lt;?php
  class Site extends CI_Controller {
  
  function index(){
  
      $this-&gt;load-&gt;view('option_view');
  }
  
  function create(){
  
      $data = array(
          'subject' =&gt; $this-&gt;input-&gt;post('subject'),
          'body' =&gt; $this-&gt;input-&gt;post('body')
      );
  
      $this-&gt;Site_model-&gt;add_record($data);
      $this-&gt;index();
  
  }
  
  }
  
  
  ?&gt;
  </code></pre>
  
  <p>model:</p>
  
  <pre><code>&lt;?php
  
  class Site_model extends CI_Model {
  
  function get_records()
  
  {
      $query = $this-&gt;db-&gt;get('items');
      return $query-&gt;result();
  }
  
  function add_record()
  {
      $this-&gt;db-&gt;insert('items', $data);
      $return;
  }
  
  function update_record()
  {
      $this-&gt;db-&gt;where('id', 1);
      $this-&gt;db-&gt;update('items', $data);
  
  }
  
  function delete_record()
  {
      $this-&gt;db-&gt;where('id', $this-&gt;url-&gt;segment(3));
      $this-&gt;db-&gt;delete('items');
  
  }
  
  }
  
  
  
  
  
  ?&gt;
  </code></pre>
  
  <p>and the view:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;
  
  &lt;title&gt;option_view&lt;/title&gt;
  &lt;style type="text/css" media="screen"&gt;
  label {display:block;}
  &lt;/style&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;h2&gt;Create&lt;/h2&gt;
  &lt;?php echo form_open('site/create'); ?&gt;
  
  &lt;p&gt;
      &lt;/label for="subject"&gt;Subject&lt;/label&gt;
      &lt;input type="text" name="subject" id="subject"&gt;
  &lt;/p&gt;
  
  &lt;p&gt;
      &lt;/label for="body"&gt;Body&lt;/label&gt;
      &lt;input type="text" name="body" id="body"&gt;
  &lt;/p&gt;
  &lt;p&gt;
  &lt;input type="submit" value="Submit"&gt;    
  &lt;/p&gt;
  &lt;?php echo form_close();?&gt;
   &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>
  
  <p>What do you guys reckon?</p>
  
  <p>Much appreciated</p>