this is what my database looks like after inserting all the data
因此,我从上一个文件创建了一个数组,在此循环中,它应检查文件中的每个索引,并在检查后将其存储在变量$ filename中。在成功输入前一个文件的所有字段后,成功将其插入数据库,但无法在照片列中上传文件,请帮助我不知道错误在哪里,因为它不会在我的if语句中回显错误,还在学习存储文件数组的情况,请帮忙。
for ($i=0; $i < $loop; $i++) {
$filename = NULL;
$sellingPrice = $_POST['unit_price'][$i]/$_POST['quantity'][$i];
if (isset($_FILES['prodPhoto'][$i]) && count($_FILES['prodPhoto'][$i]) > 4) {
if ($_FILES['prodPhoto']['type'][$i] == "image/png" || $_FILES['prodPhoto']['type'][$i] == "image/jpeg") {
if ($_FILES['prodPhoto']['size'][$i] <= 10000000) {
$filename = "../prod_images".$_FILES['prodPhoto']['name'][$i];
move_uploaded_file($_FILES['prodPhoto']['tmp_name'][$i], $filename);
}
}
}
$insertProduct = "INSERT INTO `products` (prod_name, `type`, `desc`,
`unit_price`, `qty`, `status`, `photo`, `trans_id`, `supplier_id`) VALUES ('{$_POST['prod_name'[$i]}',
'{$_POST['productType'][$i]}',
'{$_POST['desc'][$i]}',
".$sellingPrice.",
'{$_POST['quantity'][$i]}',
'available',
'{$filename}',
".$transac_id.",
'{$_POST['addSupplier'][$i]}' )";
$productResult = mysqli_query($conn,$insertProduct);
if ($productResult) {
echo "SUCCESSFULLY INSERTED";
}else{
echo mysqli_error($conn);
}
}