Uploading Image in db using Codeigniter 3.0.1
<p>i have read many forms/answer didn't helped me much on CI 3.0+. Trying to upload image path to mysql database. It seems like my Update query is not working (the image column doesn't have anything before running query). Here's my controller which's handling the upload thingy:</p>

<p>i have taken it from CI documentation <strong>upload.php</strong></p>

<pre><code>&lt;?php

class Upload extends CI_Controller {

    public function __construct()
    {
            parent::__construct();
            // $this-&gt;load-&gt;helper(array('form', 'url'));
            $this-&gt;load-&gt;library('upload');
    }

    public function index()
    {
            $this-&gt;load-&gt;view('layouts/header');
            $this-&gt;load-&gt;view('home_page', array('error' =&gt; ' ' ));
            $this-&gt;load-&gt;view('layouts/footer');
    }

    public function do_upload()
    {

            $config['upload_path']          = './uploads/'; #$this-&gt;config-&gt;item('base_url').
            $config['allowed_types']        = 'gif|jpg|png|jpeg';
            // $config['max_size']             = 100;
            // $config['max_width']            = 1024;
            // $config['max_height']           = 768;

            // $this-&gt;load-&gt;library('upload', $config);

            $this-&gt;upload-&gt;initialize($config);

            if ( ! $this-&gt;upload-&gt;do_upload('userfile'))
            {
                    $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors('&lt;p&gt;','&lt;/p&gt;'));

                    $this-&gt;load-&gt;view('layouts/header');
                    $this-&gt;load-&gt;view('home_page', $error);
                    $this-&gt;load-&gt;view('layouts/footer');
            }

            else
            {

                    $this-&gt;load-&gt;model('model_edit');
                    $id = $this-&gt;session-&gt;userdata('id');
                    $data = array('upload_data' =&gt; $this-&gt;upload-&gt;data());
                    $image['img'] = $this-&gt;upload-&gt;data('file_name');


                    $this-&gt;model_edit-&gt;update_dp($id, $data);

                     #base_url().'upload/'.

                    $this-&gt;load-&gt;view('layouts/header');
                    // echo $id;
                    $this-&gt;load-&gt;view('home_page', $image);
                    $this-&gt;load-&gt;view('layouts/footer');
            }
    }
    }
    ?&gt;
</code></pre>

<p>this is my model class <strong>model_edit.php</strong></p>

<pre><code>&lt;?php

class Model_edit extends CI_Model
{

public function __construct()
{
    parent::__construct();
}
public function update_dp($id, $data) {

    $image_path = $this-&gt;upload-&gt;data('file_path');
    $sql = "UPDATE users SET images = '{$image_path}' WHERE id = '{$id}' LIMIT 1";
    $result = $this-&gt;db-&gt;query($sql);
    $row = $this-&gt;db-&gt;affected_rows();

    if ($row) {
        return $image_path;
    }
    else
    return FALSE;       
 } 
}
?&gt;
</code></pre>

<p>This is the view i'm using <strong>home_page.php</strong></p>

<pre><code>&lt;?php
$session_data = $this-&gt;session-&gt;userdata('logged_in');
$check = $this-&gt;session-&gt;userdata('remember_me');

?&gt;
&lt;div class="container"&gt;
&lt;div class="row"&gt;
    &lt;?php include('navbar.php'); ?&gt;
&lt;/div&gt;
&lt;div class="row"&gt;
    &lt;div class="col-xs-10"&gt;
        &lt;?php

            if ($check) 
            {?&gt;
            &lt;div class="row"&gt;
              &lt;div class="col-xs-4 col-xs-3"&gt;
              &lt;?php if (isset($upload_data)) 
              {
                echo "Successfully Uploaded DP";
                echo $img;
                ?&gt;
                &lt;img src="&lt;?php echo $img; ?&gt;"/&gt;
                &lt;?php
              }?&gt;               
                &lt;?php if(isset($error))echo $error;  echo form_open_multipart('upload/do_upload');?&gt;

                &lt;input type="file" name="userfile"/&gt;
                &lt;br /&gt;
                &lt;input type="submit" name="submit" value="upload" /&gt;

                &lt;/form&gt;
              &lt;hr&gt;
              &lt;/div&gt;
              &lt;div class="col-xs-6 col-xs-5"&gt;

              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="row"&gt;  
              &lt;div class="col-xs-4 col-xs-3"&gt;
              &lt;label class="text-center"&gt; User Information &lt;/label&gt;&lt;a href="edit"&gt;&lt;span class="glyphicon glyphicon-pencil pull-right"&gt;&lt;/span&gt;&lt;/a&gt;
              &lt;br&gt;&lt;br&gt;
                &lt;label&gt;Email: &lt;/label&gt;
                &lt;br&gt;
                &lt;?php echo $session_data['email'];?&gt;
                &lt;br&gt;&lt;br&gt;
                &lt;label&gt;Display Name: &lt;/label&gt;
                &lt;br&gt;
                &lt;?php echo $session_data['name'];?&gt;
                &lt;br&gt;&lt;br&gt;
                &lt;label&gt;Username: &lt;/label&gt;
                &lt;br&gt;
                &lt;?php echo $session_data['username'];?&gt;
                &lt;br&gt;&lt;br&gt;
                &lt;a href="logout"&gt;Logout&lt;/a&gt;
              &lt;/div&gt;
             &lt;/div&gt;

            &lt;?php

            }
            else
            {
                // session_set_cookie_params(0);
                 include('browser_triger.php');
                 $session_data['username'];
                 $session_data['name'];
                 $session_data['email'];
            }
        ?&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>
</p>