您的SQL语法有错误;检查与您的MariaDB服务器版本对应的手册,以便在第2行'','1','7','123tw')附近使用正确的语法
提交表单时出现上述错误。
<?php
session_start();
$branch=$_SESSION['branch'];
include('../dist/includes/dbcon.php');
$name = $_POST['prod_name'];
$price = $_POST['prod_price'];
$desc = $_POST['prod_desc'];
$supplier = $_POST['supplier'];
$reorder = $_POST['reorder'];
$category = $_POST['category'];
//$quantity = $_POST['prod_qty'];
$serialn = $_POST['serialn'];
$query2=mysqli_query($con,"select * from product where prod_name='$name' and branch_id='$branch'")or die(mysqli_error($con));
$count=mysqli_num_rows($query2);
if ($count>0)
{
echo "<script type='text/javascript'>alert('Product already exist!');</script>";
echo "<script>document.location='product.php'</script>";
}
else
{
$pic = $_FILES["image"]["name"];
if ($pic=="")
{
$pic="default.gif";
}
else
{
$pic = $_FILES["image"]["name"];
$type = $_FILES["image"]["type"];
$size = $_FILES["image"]["size"];
$temp = $_FILES["image"]["tmp_name"];
$error = $_FILES["image"]["error"];
if ($error > 0)
{
die("Error uploading file! Code $error.");
}
else{
if($size > 100000000000) //conditions for the file
{
die("Format is not allowed or file size is too big!");
}
else
{
move_uploaded_file($temp, "../dist/uploads/".$pic);
}
}
}
mysqli_query($con,"INSERT INTO product(prod_name,prod_price,prod_desc,prod_pic,cat_id,reorder,supplier_id,branch_id,serialn)
VALUES('$name','$price','$desc','$pic','$category', $reorder','$supplier','$branch','$serialn')")or die(mysqli_error($con));
echo "<script type='text/javascript'>alert('Successfully added new product!');</script>";
echo "<script>document.location='product.php'</script>";
}
?>
答案 0 :(得分:0)
您似乎在$reorder'
之前错过了单引号?
答案 1 :(得分:0)
SQL INSERT查询出错。
mysqli_query($con,"INSERT INTO product(prod_name,prod_price,prod_desc,prod_pic,cat_id,reorder,supplier_id,branch_id,serialn)
VALUES('$name','$price','$desc','$pic','$category','$reorder','$supplier','$branch','$serialn')")or die(mysqli_error($con))
现在试试..
答案 2 :(得分:0)
在'
尝试此代码之前,您已错过$reorder
mysqli_query($con,"INSERT INTO product(prod_name, prod_price, prod_desc ,prod_pic, cat_id, reorder, supplier_id, branch_id, serialn) VALUES ('$name', '$price', '$desc', '$pic', '$category', '$reorder', '$supplier', '$branch', '$serialn')")or die(mysqli_error($con))or die(mysqli_error($con));