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();
}
}
}