title: Pass variable from controller to view and use the variable to display the data
body: <pre><code>Severity: Notice
  
  Message: Undefined variable: blog_data
  
  Filename: views/savedata.php
  
  Line Number: 4
  
  Backtrace:
  
  File: /Applications/MAMP/htdocs/success_story_ci/application/views/savedata.php
  Line: 4
  Function: _error_handler
  
  File: /Applications/MAMP/htdocs/success_story_ci/application/controllers/Story.php
  Line: 31
  Function: view
  
  File: /Applications/MAMP/htdocs/success_story_ci/index.php
  Line: 315
  Function: require_once
  </code></pre>
  
  <pre><code>
      public function savedata(){
  
          if(!empty($this-&gt;input-&gt;post())){
  
              $data = array(
                            'cluster_det' =&gt; $this-&gt;input-&gt;post('Clust_det'),
                            'need_of_activity' =&gt; $this-&gt;input-&gt;post('need_of_the_activity'),
                            'intervention' =&gt; $this-&gt;input-&gt;post('intervention'),
                            'impact' =&gt; $this-&gt;input-&gt;post('impact'),
                            'key_stakeholders' =&gt; $this-&gt;input-&gt;post('Key_stakeholders'),
                            'beneficiaries' =&gt; $this-&gt;input-&gt;post('beneficiaries'),
                            'activity_det' =&gt; $this-&gt;input-&gt;post('activity_det'),
                            'reference_contact' =&gt; $this-&gt;input-&gt;post('reference_contact'),
                            'image' =&gt; 'imageaddress',//$this-&gt;input-&gt;post('image')
                            'title' =&gt; $this-&gt;input-&gt;post('title')
                            );
  
              $res = $this-&gt;db-&gt;insert('blog', $data);
              $id = $this-&gt;db-&gt;insert_id();
              $this-&gt;db-&gt;select('*');
              $this-&gt;db-&gt;from('blog');
              $this-&gt;db-&gt;where('id', $id);
              $blog_data = $this-&gt;db-&gt;get();
  
              $this-&gt;load-&gt;view('savedata', $blog_data);
  
              echo 'data saved';
              return true;
          }
  
      }
  
      public function index()
      {
          $this-&gt;load-&gt;view('savedata');
      }
  
  </code></pre>
  
  <p>the above code is to pass a variable to the view ie the data insert command and the id from the last record so the last record is passed as variable <code>$blog_data</code> to view. 
  Also required to send the variable at the view with codeigniter to display the blog entry. </p>