I am developing an e-commerce site and am confused about this.
- Customers come on the site and add some products to the cart.
- Customers click on the checkout link if already logged in, then will go to the "thanks" page (this is your order number, total price, etc.).
I want to insert the total price into Order table.
<?php
session_start();
include('../includes/dbfunctions.php');
if(!isset($_SESSION["id"]))
{
header("location:order_login.php");
}
if(isset($_SESSION['id']))
{
$id=$_SESSION["id"];
$email=$_SESSION["email"];
$name=$_SESSION['name'];
$contact=$_SESSION["contact"];
$mysqli->query("insert into orders(user_id,user_name,contact_no,email)values('$id','$name','$contact','$email')");
$result=$mysqli->query("select order_id from orders where user_id='$id' ORDER BY order_id desc limit 1");
$obj=$result->fetch_object();
$order_id=$obj->order_id;
}
?>
<form action="#" method="post" enctype="multipart/form-data">
<div class="table-responsive">
<?php
//Display of cart
if(isset($_SESSION["products"]))
{
$total = 0;
$qty=0;
?>
<?php
foreach ($_SESSION["products"] as $cart_itm)
{
$product_qty = $cart_itm["qty"];
$product_code=$cart_itm["product_code"];
$image=$cart_itm["pic"];
$product_name=$cart_itm["name"];
echo '<img src="../image/product/'.$image.'"width="120px" height="94px">';
echo 'ucwords($product_name)';
echo 'ucwords($product_code)';
echo 'ucwords($product_qty)';
$subtotal = ($cart_itm["price"]*$product_qty);
$total = ($total + $subtotal);
echo '$subtotal';
$qty=($product_qty+$qty);
$mysqli->query("insert into order_details(user_id,img,product_name,product_code,qty,sub_total,order_id)values('$id','$image','$product_name','$product_code','$product_qty','$subtotal',$order_id)");
}
?>
</form>