File "add_product_id-20250916184327.php"
Full Path: /home/sasslijg/public_html/actions/add_product_id-20250916184327.php
File size: 2.22 KB
MIME-type: text/x-php
Charset: utf-8
<?php
session_start();
include "../admin/database.php" ;
$user_id=NULL;
$user_id=session_id();
$product_id=$_POST['product_id'];
$quantity= $_POST['quantity'];
$res="SELECT * from temp_cart where user_id='$user_id' ";
$ress = db::getRecords($res);
if($ress!=null)
{
$res1="SELECT * from temp_cart where product_id='$product_id' && user_id='$user_id'";
$ress1 = db::getRecord($res1);
if($ress1!=null){
$data=$ress1['product_id'];
// echo "$data";
if($product_id==$data)
{
$myyquan=$ress1['quantity'];
$newquan=$quantity+$myyquan;
$query="SELECT * from product where id='$product_id'";
$rec=db::getRecord($query);
$total = $newquan *$rec['price'];
$query = "UPDATE temp_cart SET quantity='$newquan',total='$total' where product_id='$product_id' && user_id='$user_id'";
$run = db::query($query);
echo "Product Quantity Added To Cart.";
}
else
{
$query="SELECT * from product where id='$product_id'";
$rec=db::getRecord($query);
$total = $quantity *$rec['price'];
$query="INSERT into temp_cart (user_id,product_id,quantity,total) VALUES ('$user_id','$product_id','$quantity','$total')";
$insert=db::query($query);
echo "Product Added To Cart.";
}
}
else{
$query="SELECT * from product where id='$product_id'";
$rec=db::getRecord($query);
$total = $quantity *$rec['price'];
$query="INSERT into temp_cart (user_id,product_id,quantity,total) VALUES ('$user_id','$product_id','$quantity','$total')";
$insert=db::query($query);
echo "Product Added To Cart.";
}
}
else{
$query="SELECT * from product where id='$product_id'";
$rec=db::getRecord($query);
$total = $quantity *$rec['price'];
$query="INSERT into temp_cart (user_id,product_id,quantity,total) VALUES ('$user_id','$product_id','$quantity','$total')";
$insert=db::query($query);
echo "First Product Added To Cart.";
}
?>