Php 如何基于上传表单将图像插入数据库

Php 如何基于上传表单将图像插入数据库,php,Php,我想插入到数据库的图像,在做一个上传表单的基础上 我的查询工作正常,在提交表单时可以插入除图像以外的所有字段 但是,当我更改代码将图像添加到数据库中时, 代码不再工作,它不会将我的字段插入数据库 有人能告诉我,在点击提交按钮后,为了将我的图像插入数据库,我能做些什么吗 <?php if(isset($_POST['description'])){ $product_name = mysql_real_escape_string($_POST['product_name']);

我想插入到数据库的图像,在做一个上传表单的基础上

我的查询工作正常,在提交表单时可以插入除图像以外的所有字段 但是,当我更改代码将图像添加到数据库中时, 代码不再工作,它不会将我的字段插入数据库

有人能告诉我,在点击提交按钮后,为了将我的图像插入数据库,我能做些什么吗

  <?php
if(isset($_POST['description'])){
    $product_name = mysql_real_escape_string($_POST['product_name']);
    $product_price = mysql_real_escape_string($_POST['product_price']);
    $category = mysql_real_escape_string($_POST['category']);
    $subcategory = mysql_real_escape_string($_POST['subcategory']);
    $product_description = mysql_real_escape_string($_POST['description']);
    $product_package = mysql_real_escape_string($_POST['product_package']);
    $product_image = mysql_real_escape_string($_POST['product_image']);




$sql = mysql_query("SELECT id FROM supermarket WHERE description='$product_description' LIMIT 1");
$productMatch = mysql_num_rows($sql);
if($productMatch > 0) {
    echo "Sorry you tried to place a duplicate 'Product Description' into the system, <a href='invertorylist.php'>click here</a>";
    exit();
}

//add name of image hear
$newname = "$product_description.jpg";

//Add this prouct into the database now
$sql = mysql_query ("INSERT INTO supermarket (category,subcategory,name,description,image,packaging,price)
VALUES ('$category','$subcategory','$product_name','$product_description',$product_image','$product_package','$product_price')");




//place image in the folder
move_uploaded_file($_FILES['fileField']['tmp_name'],"images/$newname");
    header("location: inventorylist.php"); 
    exit();

}

为什么不保存图像,并将文件路径插入数据库?这是什么意思?因为从一开始,我的数据库中就有图像..&&我正在根据描述本身显示所有图像。我的意思是mysql数据库您可以使用base64encode对图像文件进行字符串化,以便将其作为文本保存到数据库中,或者您可以将其存储为二进制文件,但它更高级-这两个都不是真正的建议。是否有更好的方法将其放入数据库中?
//add name of image hear
$newname = "$product_description.jpg";

//Add this prouct into the database now 

$sql = mysql_query ("INSERT INTO supermarket (category,subcategory,name,description,image,packaging,price) VALUES ('$category','$subcategory','$product_name','$product_description','$newname','$product_package','$product_price')");


  //place image in the folder

move_uploaded_file($_FILES['fileField']['tmp_name'],"images/$newname");
    header("location: inventorylist.php"); 
    exit(); }