0

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.

Error is: Undefined index: pic in F:\xampp\htdocs\admin_with_oops\HTML\index.php on line 20

index.php is:

<?php
if(isset($_POST['insertcollege']))
    {
        $userprofileobj->insert_college($_POST['college_name'],$_POST['college_descr'],$_POST['pic']);
        echo $userprofileobj->error;            
    }


?>


<form action="" method="POST" enctype="multipart/form-data">
      <div class="control-group">
          <label class="control-label">College Name :</label>
          <div class="controls">
            <input type="text" class="span11" placeholder="First name" name="college_name" required />
          </div>
        </div>
         <div class="control-group">
          <label class="control-label">Image</label>
          <div class="controls">
            <input type="file" name="pic" />
          </div>
        </div>
        <div class="controls">
        <label class="control-label">College Description :</label>
          <textarea class="textarea_editor span12" rows="6" placeholder="Enter text ..." name="college_descr"></textarea>
        </div>
         <div class="form-actions">
              <input type="submit" value="SAVE" name="insertcollege" class="btn btn-success">
            </div>
      </form>

classes.php is:

class operations{

public $user_email;
public $error;
public $con;


public function __construct()
{       
$this->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->con->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->error = "Inserted Successfully";
        header("location:collegename.php");
        ob_end_clean(); 
    }
}
}
vinod jaiswal
  • 89
  • 2
  • 11
  • With input type of `pic` being a `file`, what exactly are you trying to achieve with `$_POST['pic']`? I believe arguments passed to the function `insert_college()` aren't as its intended to be. – Saharsh May 25 '18 at 08:54
  • Thank you for reply. I want to upload image in table. Image name is pic. which is send to member function insert_college. And in classes.php, image will be save in folder and name will be in table. – vinod jaiswal May 25 '18 at 09:02
  • Am I on wrong way? Please help to solve it. – vinod jaiswal May 25 '18 at 09:20

0 Answers0