使用PHP将数据插入数据库

时间:2016-09-01 05:21:36

标签: php sql

我使用此代码将图像插入数据库但有些错误不断弹出

代码:

<?php
    if(isset($_POST ['insert_post']))
    {
        $product_title=$_POST['product_title'];
        $product_cat=$_POST['product_cat'];
        $product_brand=$_POST['product_brand'];
        $product_price=$_POST['product_price'];
        $product_desc=$_POST['product_desc'];
        $product_keyword=$_POST['product_keyword'];
        $product_img=$_FILES['product_image']['name'];
        $product_img_tmp=$_FILES['product_image']['tmp_name'];   
    }

    echo $insert_product="insert into products 
        (product_cat, product_brand, product_title, product_price, product_desc, product_image, product_keyword) values
        ('$product_cat','$product_brand','$product_title','$product_price','$product_desc','$product_img','$product_keyword')";
?>

1 个答案:

答案 0 :(得分:0)

制作product_image列数据类型BLOBMEDIUMBLOBLONGBLOB。然后使用file_get_contents()函数获取文件数据。

$product_img_tmp = file_get_contents($_FILES['product_image']['tmp_name']);

并将其存储在您的数据库中。