这两行出现问题:
$product_image = $_FILES['product_image']['name'][0];
$product_image_tmp = $_FILES['product_image']['tmp_name'][0];
以下是代码:
<?php
if(isset($_POST['insert_post'])){
$product_title = $_POST['product_title'];
$product_cat = $_POST['product_cat'];
$product_brand = $_POST['product_title'];
$product_price = $_POST['product_price'];
$product_desc = $_POST['product_desc'];
$product_keywords = $_POST['product_keywords'];
$product_image = $_FILES['product_image']['name'][0];
$product_image_tmp = $_FILES['product_image']['tmp_name'][0];
move_uploaded_file($product_image_tmp,"product_images/$product_image");
echo $insert_product = "insert into products
(product_cat,product_brand,product_title,product_price,product_desc,product_image,product_keywords)
values('$product_cat','$product_brand','$product_title','$product_price','$product_desc','$product_image','$product_keywords')";
$insert_pro = mysqli_query($con,$insert_product);
if($insert_pro){
echo "<script>alert('Product Has Been Inserted')</script>";
echo "<script>window.open('insert_product.php','_self')</script>";
}
}
?>
答案 0 :(得分:0)
确保您已将enctype="multipart/form-data"
添加到form
元素
并确保您的文件类型输入名为product_image
答案 1 :(得分:0)
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp_name'];
试试吧