title: How to insert upload image name into database in codeigniter
body: <p>My image is upload into the respective folder and I try to save it name to database but still can and error occur</p>
  
  <pre><code>public function add_posts() {
  
                  $this-&gt;load-&gt;helper('form');
                  $this-&gt;load-&gt;library('form_validation');
                  $this-&gt;form_validation-&gt;set_rules('title','Title','required');
                  if($this-&gt;form_validation-&gt;run() === FALSE) {
                       $this-&gt;load-&gt;view('posts/add');
                  }
                  else {
                      $this-&gt;load-&gt;model('Posts_Model');
                      $data = array(
                          'title' =&gt; $this-&gt;input-&gt;post('title'),
                          'body' =&gt; $this-&gt;input-&gt;post('body'),
                          'cover' =&gt; $this-&gt;input-&gt;post('cover'));
                          //---image upload ---//
                          $config['upload_path']          = './uploads/';
                          $config['allowed_types']        = 'gif|jpg|png';
  
                          $this-&gt;load-&gt;library('upload', $config);
                          if ( ! $this-&gt;upload-&gt;do_upload('cover')) {
                              $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors());
                              $this-&gt;load-&gt;view('posts/add', $error);
                          } else {
                              $data =  $this-&gt;upload-&gt;data();
                              $cover = $data['file_name'];
                              $data['cover'] = $cover;
                          }
  
                          //---End image upload---//
                      $this-&gt;Posts_Model-&gt;insert($data);
  
                      $query = $this-&gt;db-&gt;get("posts");
                      $data['records'] = $query-&gt;result();
                      $this-&gt;load-&gt;view('posts/index',$data);
                  }
  
              }
  </code></pre>
  
  <p>Here is my function in my controller only the name of image (cover) can't insert into database and other work respectively.
  The Database Error Occur</p>
  
  <blockquote>
    <p>A Database Error Occurred</p>
    
    <p>Error Number: 1054</p>
    
    <p>Unknown column 'file_name' in 'field list'</p>
  </blockquote>
  
  <pre><code>INSERT INTO `posts` (`file_name`, `file_type`, `file_path`, `full_path`, `raw_name`, `orig_name`, `client_name`, `file_ext`, `file_size`, `is_image`, `image_width`, `image_height`, `image_type`, `image_size_str`, `cover`) VALUES ('la.jpg', 'image/jpeg', '/vagrant/uploads/', '/vagrant/uploads/la.jpg', 'la', 'la.jpg', 'la.jpg', '.jpg', 22.38, 1, 1200, 700, 'jpeg', 'width=\"1200\" height=\"700\"', 'la.jpg')
  </code></pre>
  
  <p>Filename: models/Posts_Model.php</p>
  
  <p>Line Number: 8</p>