problem with SQL execution in shopping cart

Discussion in 'PHP' started by Kyriakos, May 20, 2008.

  1. #1
    hi everyone,

    i have a shopping cart with those SQL queries: add product to cart, update product (product quantity) and delete product from cart. when i execute the add, update or delete SQL query the SELECT QUERY it doesn't work. These are my queries:
    <?php if ($cart == "add") {
    $sql="INSERT INTO cart (sessionid, code, model,descr,pricer,qty) VALUES ('".$sessionid."','".$code."','".$model."','".$descr."','".$pricer."','".$qty."')";
    
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
    mysql_close($con) 
    ?><?php } else { ?><?php } ?>
    
    <?php if ($cart == "del") {
    mysql_query("DELETE FROM cart WHERE code='".$code."'");
    
    mysql_close($con);
    ?>deleted ok<?php } else { ?><?php } ?>
    
    <?php if ($cart == "upd") {
    mysql_query("UPDATE cart SET qty='".$qty."' WHERE code='".$code."'");
    
    mysql_close($con);
    ?>updated ok<?php } else { ?><?php } ?>
    
    <?php
    $result = mysql_query("SELECT * FROM cart WHERE sessionid='".$sessionid."' ORDER BY pricer");
    ?>
    
    PHP:
    another problem. how i can display a message (This product is already in the cart) when the visitor adds a product that is already in the cart?

    thanks in advance.
     
    Kyriakos, May 20, 2008 IP