嘿伙计们我遇到了一个有趣的问题。我使用此代码用于我的其他网站,这些网站运行良好。现在我只是更改变量等,我得到空查询错误。我从一行到另一行检查了我的代码,但没有发现任何错误。
我感谢任何帮助:)
以下是代码:
<h1 class="text-center">Insert New Product</h1>
<form method="POST" action="index.php?insert_product" enctype="multipart/form-data">
<table id="form_table">
<tr>
<td class="valign">Title:</td>
<td class=""><input type="text" name="product_title" required></td>
</tr>
<tr>
<td class="valign">Price:</td>
<td class=""><input type="text" name="product_price" required></td>
</tr>
<tr>
<td class="valign">Category:</td>
<td class="">
<select name="product_cat" required>
<option value="" disabled selected hidden>Please Choose...</option>
<?php getCats_select(); ?>
</select>
</td>
</tr>
<tr>
<td class="valign">Brand:</td>
<td class="">
<select name="product_brand" required>
<option value="" disabled selected hidden>Please Choose...</option>
<?php getBrands_select(); ?>
</select>
</td>
</tr>
<tr>
<td class="valign">Keywords:</td>
<td class=""><input type="text" name="product_keywords" required></td>
</tr>
<tr>
<td class="valign">Image:</td>
<td class=""><input type="file" name="product_image" required></td>
</tr>
<tr>
<td class="valign">Description:</td>
<td class=""><textarea name="product_desc"></textarea></td>
</tr>
<tr>
<td class="valign">Specifications:</td>
<td class=""><textarea name="product_spec"></textarea></td>
</tr>
<tr class="submit">
<td></td>
<td class="f-right"><input class="button" type="submit" name="submit" value="Upload"></td>
</tr>
</table>
</form>
<?php
if (isset($_POST['submit'])) {
$product_title = $_POST['product_title'];
$product_price = $_POST['product_price'];
$product_cat = $_POST['product_cat'];
$product_brand = $_POST['product_brand'];
$product_keywords = $_POST['product_keywords'];
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp_name'];
$product_desc = addslashes($_POST['product_desc']);
$product_spec = addslashes($_POST['product_spec']);
move_uploaded_file($product_image_tmp, "product_images/$product_image");
$insert_products = "INSERT INTO products (product_cat, product_brand, product_title, product_price, product_desc, product_spec, product_image, product_keywords)
VALUES ('$product_cat', '$product_brand', '$product_title', '$product_price', '$product_desc', '$product_spec', '$product_image', '$product_keywords')";
$run_products = mysqli_query($con, $insert_products);
$run_query = mysqli_query($con, $run_products);
echo "<script>alert('Product has been uploaded succesfully!')</script>";
echo "<script>window.open('index.php?insert_product','_self')</script>";
}
?>
答案 0 :(得分:0)
$run_products = mysqli_query($con, $insert_products);
$run_query = mysqli_query($con, $run_products);
你为什么要做第二个mysqli_query并运行第一个mysqli_query的结果?
现在你有几秒mysqli_query的错误,因为现在它正在处理第一个mysqli_query的结果。 mysqli_query需要查询而不是查询结果
答案 1 :(得分:0)
$run_products = mysqli_query($con, $insert_products);
$run_query = mysqli_query($con, $run_products);
echo "<script>alert('Product has been uploaded succesfully!')</script>";
echo "<script>window.open('index.php?insert_product','_self')</script>";
您将函数mysqli_query放入另一个mysqli_query函数中。这显然不起作用,因为它尝试运行由第一个查询的结果组成的查询。
将其替换为:
if(mysqli_query($con, $insert_products)){
echo "<script>alert('Product has been uploaded succesfully!')</script>";
echo "<script>window.open('index.php?insert_product','_self')</script>";
}
答案 2 :(得分:-1)
OOOOoookkay ......我找到了一些东西。以某种方式img上传是问题。如果我从INSERT行中删除它,就可以正常工作......
谢谢你的帮助,无论如何:)