Jump to content

Help need for shopping cart for multiple users or visitors


vinpkl

Recommended Posts

Hi all

 

I am working on a shopping cart module. At present my script add a product in cart and if its already in the cart then it updates the quantity.

 

This works well for the single visitor to the website. But if there are multiple visitors or users at the same time then it will mess up the cart contents with others.

 

what should i add in my script.

 

This is my shopping cart script

<?php 
require_once("config.php"); 

$_SESSION['product_id']=$_REQUEST['product_id']; 
$id=$_SESSION['product_id'];
$id=$_REQUEST['id'];
echo $id;

$qry="SELECT * FROM product_table WHERE product_id=$id";
$result=mysql_query($qry)or die (mysql_error()); 
$row=mysql_fetch_array($result);

$pid=$id;
$image=$row['image'];
$product_name=$row['product_name'];
$price=$row['price'];
$shipping_cost=$row['shipping_cost'];
$total_cost=$row['price']+$row['shipping_cost'];

$qry="SELECT product_id from cart_table where product_id=$id";
$result=mysql_query($qry)or die (mysql_error()); 
$row=mysql_fetch_array($result);

if($id != $row['product_id'])
{
$qry="INSERT INTO cart_table(product_id,image,product_name,price,quantity,shipping_cost,total_cost) 
VALUES($id,'$image', '$product_name', $price, 1, $shipping_cost, $total_cost)";
$result=mysql_query($qry)or die(mysql_error());
}
else
{
$qry="UPDATE cart_table SET product_id=$pid,image='$image',product_name='$product_name',price=$price,quantity=quantity+1,shipping_cost=$shipping_cost,total_cost=$total_cost where product_id=$id"; 
$result=mysql_query($qry)or die(mysql_error());
}
?>

 

vineet

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.