//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 –