图像未插入phpmyadmin数据库

时间:2017-06-11 18:36:27

标签: php mysql phpmyadmin

我正在使用FILE类型的输入字段,以便将图像插入到我的数据库中,然后在前端查看te图像。

这是我在我的pho文件中用来插入数据的代码:

function insert_product(){
    try{
        global $conn;
        //prepare statement 
        $statement = $conn->prepare("insert into products (product_name, product_brand, product_category, product_image, product_description, product_price, product_keywords) values (:product_name, :product_brand, :product_category, :product_image, :product_description, :product_price, :product_keywords)");
        //bind parametes
        $statement ->bindParam(':product_name', $product_name);         
        $statement ->bindParam(':product_brand', $product_brand);
        $statement ->bindParam(':product_category', $product_category);
        $statement ->bindParam(':product_name', $product_name);
        $statement ->bindParam(':product_price', $product_price);
        $statement ->bindParam(':product_description', $product_description);
        $statement ->bindParam(':product_keywords', $product_keywords);

        // executing the statement
        $product_name = $_POST['product_name'];
        $product_brand = $_POST['product_brand'];
        $product_category = $_POST['product_category'];
        $product_price = $_POST['product_price'];
        $product_description = $_POST['product_description'];
        $product_keywords = $_POST['product_keywords'];
        //getting the image from the field
        $product_image = $_FILES['product_image']['name'];
        $product_image_tmp = $_FILES['product_image']['tmp_name'];
        move_uploaded_file($product_image_tmp,"product_images/$product_image");
        $statement->execute();
        header('Location: index.php');
    }
    catch(PDOException $e){
        echo 'Error: ' . $e->getMessage();
    }
}

当我尝试插入数据时,我看到了这个错误:

enter image description here

我检查了我的参数,并不太明白到底出了什么问题。

如何将图像插入我的数据库并在以后查看?

0 个答案:

没有答案