//Add this product into database now
$sql = "INSERT INTO products
(product_name,price,details,category,
subcategory,date_added)
VALUES ('$product_name','$price','$details','$category',
'$subcategory',now())";
//now() will add todays date in database
if($result = mysqli_query($conn,$sql)){
$pid = mysqli_insert_id($conn);//Generated an auto-generated id
//Place image in the folder
$newname = "$pid.jpg";
move_uploaded_file($_FILES['fileField']['temp_name'],"../inventory_images/$newname");//$_FILES is a global variable.
header("location: inventory_list.php");//if you will not include this line then it will add the same product again if you refresh the page.
exit();
}
else{
echo"Data didn't inserted in the database";
}
每当我运行代码它工作正常,数据被插入,但是当我检查我上传的图像的目录,没有什么夹。请尽早帮助我。我试图上传图像在目录中使用PHP
是否打开了错误报告? – MonkeyZeus
确保目录是可写的。 Chmod – Akintunde007
仔细检查您是否正试图上传到正确的文件夹。相对路径,特别是用'../',总是让我感到紧张:p –