if(isset($_POST['insert_post']))
{
//global $con;
$con=mysqli_connect("localhost","root","","ecom") or die('Error ocurred while establishing database connection');
// getting text data from feilds
$product_title=$_POST['product_title'];
$product_cat=$_POST['product_cat'];
$product_brand=$_POST['product_brand'];
$product_price=$_POST['product_price'];
$product_desc=$_POST['product_desc'];
$product_keywords=$_POST['product_keywords'];
// getting image from feilds
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp_name'];
echo "asd";
move_uploaded_file($product_image_tmp, "product_images/$product_image");
$query = "insert into products values
($product_cat','$product_brand','$product_title','$product_price','$product_desc','$product_image','$product_keywords')";
mysqli_query($con,$query) or die ("can't work!");
echo "<script>alert('Product has been inserted')</script>";
echo "<script> window.open('insert_product.php','self')</script>";
}
答案 0 :(得分:-1)
(对不起,我的英文)
您必须指定数据库列的名称
像这样:
列:
猫|品牌|标题|价格| desc |图片关键字
$query = "INSERT INTO products (cat, brand, title, price, desc, image, keywords) values ('$product_cat','$product_brand','$product_title','$product_price','$product_desc','$product_image','$product_keywords');";
我希望这是有用的