Call to a member function insert() on null. Codeigniter
<p>Hi everyone I am getting the following error when I submit my form for my CI 3 website:</p>

<blockquote>
  <p>Fatal error: Call to a member function insert() on null</p>
</blockquote>

<p>This error is occurring on line 20 which is:</p>

<pre><code>$query =  $this-&gt;db-&gt;insert('temp_subscribed_users', $data);
</code></pre>

<p>Here is the full function:</p>

<pre><code>public function add_temp_user($key)
{
    echo "hello";

    $data = array(


        'TEMP_EMAIL' =&gt; $this-&gt;input-&gt;post('email'),

        'TEMP_KEY' =&gt; $key

    );

    echo var_dump($data);

    $query =  $this-&gt;db-&gt;insert('temp_subscribed_users', $data);

    if($query)
    {

        return true;  
    }else{

        return false; 

    }
}
</code></pre>

<p>I am not sure what it means by null. The table name is correct and I did a var_dump to confirm that the array is being populated. I also made sure that I am getting into the function by echoing "hello" and it is outputting onto the page.</p>

<p>Any help is appreciated thank you!</p>

<p>Additional info: Running using XAMPP localhost.</p>