无法将PHP表单数据存储在数据库中[重复]

I am developing a sample e-commerce website built on PHP,Bootstrap and MySQLi

I am facing problem with 2 PHP pages: home.php and cart-script.php

Some relevant portion of home.php for a form with text input and button is: `

<div class="panel panel-default">
    <div class="panel-heading">
        <div class="panel-title">
            <?php TitleQuery(2); ?>
        </div>
    </div>
    <div class="panel-body">
        <center>
            <?php
                PhotoQuery(2);
            ?>
        </center>
            <p>
                <?php
                    BodyQuery(2);
                ?>
            </p>
    <form action="cart-script.php" method="POST">
        <p>
            <center>
                <input type="number" class="form-control" name="name2" placeholder="Select quantity to add:">
                </input>
            </center>
        </p>
        <input type="button" name="submit2" class="btn btn-primary btn-block" value="Add to cart">
        </input>
    </form>
</div>

`

My code for cart-script.php file is: `

session_start();
require_once("connection.php");
if(isset($_POST['submit2']))
{
    $n=int($_POST['name2']);
    $id=2;
    $query1= "SELECT ItemName,Price FROM items WHERE ItemID='2'";
    $result1=mysqli_query($con,$iquery1);
    while($row=mysqli_fetch_array($result))
    {
        $iname=$row["ItemName"];
        $p=$row["Price"];
    }
    $query = "INSERT INTO shopcart VALUES 
             (
                 '{$id}',
                 '{$iname}',
                 '{$p}',
                 '{$n}'
             )";
    $result=mysqli_query($con,$query);
}

?>`

Whenever I click on 'Add to cart' button in home.php and then check database on PHPMyAdmin on WampServer, the database has not been affected all. Where am I wrong?

</div>

You just need to submit Your form:

<input
  type="submit"
  name="submit2"
  class="btn btn-primary btn-block"
  value="Add to cart">

Your form not submitted yet

session_start();
        require_once("connection.php");
        if(isset($_POST['submit2']))
        {
            $n = $_POST['name2'];
            $id=2;
            $query1= "SELECT ItemName,Price FROM items WHERE ItemID = '2' ";
            $result1=mysqli_query($con,$query1);
            while($row=mysqli_fetch_array($result1))
            {
                $iname=$row["ItemName"];
                $p=$row["Price"];

                $query = "INSERT INTO shopcart VALUES ('$id','$iname','$p','$n') ";
                $result = mysqli_query($con,$query);
                if($result)
                {
                    echo "success";
                }
            }
        }

add then You have some undefined like $iquery1 I have updated the code it might work for you .