将这些记录插入表中时,为什么会出现mysqli_error()?

时间:2019-04-12 13:26:07

标签: php jquery mysql insert

我试图将这些记录存储到数据库中并在一个表(tbl_pizzas)中显示它们,但是当我运行此代码时,它说我有mysqli_error()。

其他说明:我将多个表合并为一个表,因此在INSERT查询中使用SELECT查询。我使用SELECT查询从我的下拉列表中提取记录。

 if($_POST)
       {
       include('connection.php');

    $name = $_POST['name']; 
    $desc = $_POST['desc']; 
    $price = $_POST['price'];

    $query=mysqli_query($con,"select * from tbl_pizzas where pizzaName='$name'")or die(mysqli_error());
            $count=mysqli_num_rows($query);     
            if ($count>0)
                {
                    echo "<script type='text/javascript'>alert('Pizza already added!');</script>";  
                echo "<script>document.location='pizza.php'</script>";  
                }
            else
            {   
                mysqli_query($con,"INSERT INTO tbl_pizzas(pizzaName, pizzaDesc, pizzaPrice, sauceID, crustID, meatID, sizeID, id) 
                   VALUES ($name, $desc, $price, 
                    (SELECT sauceID FROM tbl_sauce WHERE sauceID=@sauceID),
                    (SELECT crustID FROM tbl_crust WHERE crustID=@crustID),
                    (SELECT meatID FROM tbl_meat WHERE meatID=@meatID),
                    (SELECT sizeID FROM tbl_size WHERE sizeID=@sizeID), 
                    (SELECT id FROM users WHERE id=@id))")or die(mysqli_error());

                echo "<script type='text/javascript'>alert('Successfully added a pizza!');</script>";   
                echo "<script>document.location='pizza.php'</script>";  
            }
   }    

0 个答案:

没有答案