title: Removing mandatory option for image unable to insert the post in mysql database
body: <p>Hi i am having a page where user can insert the blogs which contains blog name,image and description.Getting the problem while inserting blogs in database.If i am removing the mandatory option for blog image unable to insert  the post into database.It is displaying blog has successfully inserted but there is no blog inserted in my database.</p>
  
  <p>Controller:</p>
  
  <pre><code>function addblogs()
  {
      $this-&gt;load-&gt;library('form_validation');
      $this-&gt;form_validation-&gt;set_error_delimiters('&lt;br /&gt;&lt;span class="error"&gt; ','&lt;/span&gt;');
      $this-&gt;form_validation-&gt;set_rules('blog_title','Blog Title');
      $this-&gt;form_validation-&gt;set_rules('description','Blog Description');        
      if($this-&gt;form_validation-&gt;run()== FALSE)   
      {       
      $data['mainpage']='blogs';
      $data['mode']='add';
      $this-&gt;load-&gt;view('templates/template',$data);
      }
      else
      {
          $this -&gt; blogs_model -&gt; insertblogs();
          $this-&gt;flash-&gt;success('&lt;h2&gt;blogs Added Successfully!&lt;/h2&gt;');
          redirect('blogs');
      }
  }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>function insertblogs()
  {               
      $data=array(        
      'blog_title'=&gt;$this-&gt;input-&gt;post('blog_title'),
      'description'=&gt;$this-&gt;input-&gt;post('description'),       
      );
       if ( $_FILES AND $_FILES['image_path']['name'])
              {
                  $file_name = $this-&gt;do_upload2();
                  if(is_array($file_name)){
                      $error['imageerror'] = $file_name['error'];
                  }
                  else
                  $data['image_path']=$file_name;
              }
              if(!isset($data['image_path']) &amp;&amp; !isset($error['imageerror']))
              $error['imageerror'] ="Please Upload an image";
              if(isset($error))return $error;     
              $this-&gt;db-&gt;insert('blogs',$data);
  
  } 
  
  function do_upload2() 
  {
      $config = array(
          'allowed_types' =&gt; 'jpg|jpeg|gif|png',
          'upload_path' =&gt; $this-&gt;image_path,
          'max_size' =&gt; 20000,
          'maintain_ratio'=&gt;FALSE,
          'width' =&gt; 90,
          'height' =&gt; 75
      );
      $this-&gt;load-&gt;library('upload', $config);
      if(!$this-&gt;upload-&gt;do_upload('image_path'))
      {
          return $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors());
      }
      else
      {
          $image_data = $this-&gt;upload-&gt;data();
          $config = array(
          'source_image' =&gt; $image_data['full_path'],
          'new_image' =&gt;$this-&gt;image_path . '/thumbs',
          'maintain_ratio' =&gt; FALSE,
          'width' =&gt; 90,
          'height' =&gt; 75
          );
          $this-&gt;load-&gt;library('image_lib', $config);
          $this-&gt;image_lib-&gt;resize();
          $filename =time().preg_replace('/[^A-Za-z0-9\s.\s-]/', '_', $image_data['file_name']);
          rename($image_data['full_path'],$image_data['file_path'].$filename);
          rename($image_data['file_path'].'thumbs/'.$image_data['file_name'],$image_data['file_path'].'thumbs/'.$filename);
          return $filename;
      }
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
              $(document).ready(function() {  
              $('#submit').click(function(){
                      if((jQuery.trim($('#image_path').val())==''))
                      {
                          alert("Please select image");
                          $('#image_path').focus();
                          return false;
                      }
                  });
              }); 
          &lt;/script&gt;           
      &lt;div class="full_w"&gt;
      &lt;div class="h_title"&gt;
          &lt;div class="lefttitle fl"&gt;
              Add Blogs
          &lt;/div&gt;
          &lt;div class="rightbutton fr"&gt;
              &lt;a  class="button cancel" href="&lt;?php echo site_url()?&gt;/blogs"&gt;Cancel&lt;/a&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;?php
          $form_attributes  = array('name'=&gt;'adds', 'id'=&gt;'adds', 'enctype' =&gt; "multipart/form-data");
          echo form_open('blogs/addblogs',$form_attributes);
      ?&gt;
  
      &lt;div class="element"&gt;
          &lt;label for="blogtitle"&gt;&lt;font color ="black"&gt;Blog Title&lt;/font&gt;&lt;/label&gt;
          &lt;input class="text err" type="text" name="blog_title" id="blog_title" value="&lt;?php echo set_value('blog_title');?&gt;"/&gt;               
      &lt;/div&gt;          
      &lt;div class="element"&gt;
          &lt;label for="description"&gt;&lt;font color ="black"&gt;Blog Description&lt;/font&gt;&lt;/label&gt;
          &lt;textarea name="description" class="ckeditor" rows="4" cols="173"&gt;&lt;/textarea&gt;
      &lt;/div&gt; &lt;br/&gt;
  
      &lt;div class="element"&gt;
          &lt;label&gt;&lt;font color ="black"&gt;Select Image:&lt;/font&gt;&lt;/label&gt;
          &lt;input class="err" type="file" name="image_path" id="image_path"/&gt;          
      &lt;/div&gt;&lt;br/&gt;
  
      &lt;div align="center"&gt;
              &lt;input type="submit" id="submit" value="Submit" /&gt;
      &lt;/div&gt; 
      &lt;div class="clear"&gt;&lt;/div&gt;
      &lt;?php echo form_close();?&gt;
      &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="clear"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>I am using codeigniter php</p>