title: how to upload image with class
body: <p>I want to save image in table with class. I tried, but it is not working.
  When I select image and click on submit. Then error comes.</p>
  
  <p><strong>Error is:</strong> Undefined index: pic in F:\xampp\htdocs\admin_with_oops\HTML\index.php on line 20 </p>
  
  <p><strong>index.php is:</strong></p>
  
  <pre><code>&lt;?php
  if(isset($_POST['insertcollege']))
      {
          $userprofileobj-&gt;insert_college($_POST['college_name'],$_POST['college_descr'],$_POST['pic']);
          echo $userprofileobj-&gt;error;            
      }
  
  
  ?&gt;
  
  
  &lt;form action="" method="POST" enctype="multipart/form-data"&gt;
        &lt;div class="control-group"&gt;
            &lt;label class="control-label"&gt;College Name :&lt;/label&gt;
            &lt;div class="controls"&gt;
              &lt;input type="text" class="span11" placeholder="First name" name="college_name" required /&gt;
            &lt;/div&gt;
          &lt;/div&gt;
           &lt;div class="control-group"&gt;
            &lt;label class="control-label"&gt;Image&lt;/label&gt;
            &lt;div class="controls"&gt;
              &lt;input type="file" name="pic" /&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="controls"&gt;
          &lt;label class="control-label"&gt;College Description :&lt;/label&gt;
            &lt;textarea class="textarea_editor span12" rows="6" placeholder="Enter text ..." name="college_descr"&gt;&lt;/textarea&gt;
          &lt;/div&gt;
           &lt;div class="form-actions"&gt;
                &lt;input type="submit" value="SAVE" name="insertcollege" class="btn btn-success"&gt;
              &lt;/div&gt;
        &lt;/form&gt;
  </code></pre>
  
  <p><strong>classes.php is:</strong></p>
  
  <pre><code>class operations{
  
  public $user_email;
  public $error;
  public $con;
  
  
  public function __construct()
  {       
  $this-&gt;con = new mysqli("localhost","root","","admin_with_oops");
  }
  public function insert_college($college_name,$college_descr,$pic)
  {
      $date1 = date("Y-m-d");
  
      $filename=$_FILES["pic"]["name"];
      $newpath="college_image/".$filename;
      $oldpath=$_FILES["pic"]["tmp_name"];
      move_uploaded_file($oldpath,$newpath);
  
      $result = $this-&gt;con-&gt;query("insert into courses (college_name,college_descr,college_image,date1,status1) VALUES ('$college_name', '$college_descr', '$filename','$date1','1')");
      if($result)
      {
          ob_start();
          $this-&gt;error = "Inserted Successfully";
          header("location:collegename.php");
          ob_end_clean(); 
      }
  }
  }
  </code></pre>