vinpkl Posted November 2, 2008 Share Posted November 2, 2008 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 https://forums.phpfreaks.com/topic/131072-help-need-for-shopping-cart-for-multiple-users-or-visitors/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.