hi

i m using this below code ref for creating shopping cart

PHP Code:
 <?php 
if (isset($_POST['pid'])) {
    
$pid $_POST['pid'];
    
$wasFound false;

    if (!isset(
$_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { 
        
$_SESSION["cart_array"] = array(array("item_id" => $pid"quantity" => 1));

        
/* query to insert items into cart */
        
$qry "INSERT into cart_table() values()";
        
    } else {
        foreach (
$_SESSION["cart_array"] as &$each_item) { 
            if (
$each_item['item_id'] == $pid) {
                
$each_item['quantity'] += 1;
                
        
/* query to update items quantity in cart */
        
$cart_update_query "UPDATE cart_table SET ....."

        
$wasFound true;
                break;
            }
        }

        if (
$wasFound == false) {
            
array_push($_SESSION["cart_array"], array("item_id" => $pid"quantity" => 1));

            
/* query to insert items into cart */
            
$qry "INSERT into cart_table() values()";
        }
    }
    
header("location: cart.php"); 
    exit();

?>
The problem :
If i insert ONE product then all is fine.

WHEN i insert SECOND different product then 2nd product is added fine But 1st product is also added again into new row.

Means i get 3rows (2 rows of 1st product and 1 row of 2nd product in database)

i should get 2rows

If i remove the INSERT QUERY from after array_push code then 2nd different product doesnt get added.

vineet