如何使用课程

时间:2018-05-25 08:47:51

标签: php class oop

我想用class保存图像。我试过了,但它没有用。 当我选择图像并单击提交时。然后错误来了。

错误是:未定义的索引:第20行的F:\ xampp \ htdocs \ admin_with_oops \ HTML \ index.php中的图片

index.php是:

<?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是:

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

0 个答案:

没有答案