I have an order page called 08012021.php
, where you can insert x amount of gloves in different kind of sizes like small, medium, large and xlarge - when the user has entered the number of gloves they want in the different kinds of sizes, they will be directed to a different page called cart.php where they can review their order.
Here, they can see the order date by the product, different kinds of sizes they have chosen and the price of each kind of glove, and the total amount of gloves and total amount price. Working fine.
If the user agrees to this, I want to insert it into my database foodorder->orders
, but I have no idea where to put the code inside my cart.php, so that when the press the button, it will insert into my database with the information.
The name of the database
is foodorder
, the table
is called orders
.
I have this code:
$gtotal = 0;
foreach($_SESSION["cart"] as $keys => $values)
{
$F_ID = $values["food_id"];
$foodname = $values["food_name"];
$price = $values["food_price"];
$small = $values["small"];
$total = ($values["small"] * $values["food_price"]);
$R_ID = $values["R_ID"];
$username = $_SESSION["login_user2"];
$order_date = date('Y-m-d');
$gtotal = $gtotal + $total;
$query = "INSERT INTO orders (F_ID, foodname, price, small, R_ID, username, order_date)
VALUES ('" . $F_ID . "','" . $foodname . "','" . $price . "','" . $small . "','" . $R_ID . "','" . $username . "','" . $order_date . "');";
$success = $conn->query($query);
}
I don't know how to place the other code in here.