一切正常,直到我决定添加新产品,但没有任何效果,图片正在上传到文件夹中,但问题出在move_uploaded_file函数中,问题是该功能正在运行并且正在移动图片,但是代码是不移至下一条指令,是否有人对此错误有任何想法?
<?php
if ($_POST) {
$productName = $_POST['productName'];
$quantity = $_POST['quantity'];
$rate = $_POST['rate'];
$brandName = $_POST['brandName'];
$categoryName = $_POST['categoryName'];
$genderName = $_POST['genderName'];
$sizeName = $_POST['sizeName'];
$productStatus = $_POST['productStatus'];
$type = explode('.', $_FILES['productImage']['name']);
$type = $type[count($type) - 1];
$url = '../assests/images/stock/' . uniqid(rand()) . '.' . $type;
if (in_array($type, ['gif', 'jpg', 'jpeg', 'png', 'JPG', 'GIF', 'JPEG', 'PNG'])) {
if (is_uploaded_file($_FILES['productImage']['tmp_name'])) {
if (move_uploaded_file($_FILES['productImage']['tmp_name'], $url)) {
$sql = "INSERT INTO product (product_name, product_image, brand_id, categories_id, quantity, price, active, status,gender_id,size_id,description,dateadded,discount)
VALUES ('$productName', '$url', '$brandName', '$categoryName', '$quantity', '$rate', '$productStatus', 1,'$genderName','$sizeName')";
if ($connect->query($sql) === true) {
echo "<SCRIPT type='text/javascript'> //not showing me this
alert('Product added !');
window.location.replace(\"http://localhost/stock/product.php\");
</SCRIPT>";
} else {
$valid['success'] = false;
$valid['messages'] = "Error while adding the members";
}
} else {
echo "lool";
}
}
}
$connect->close();
}
?>
答案 0 :(得分:0)
在代码的任何地方都看不到变量$ connect声明。您可能已禁用错误报告功能,并且脚本在
上消失if ($connect->query($sql) === true) {
因为$ connect未定义?