Q:

I can't update the product quantity in session

I'm trying to make a shopping cart with PHP.I can add products to the database, but while I was testing, I have discovered a bug.  Quantity of pieces does not change if I add the same one in addition to a previously added product.  I just want to increase the amount when it is added again from a previously added product.  But I tried two different ways, but I failed.  I may be making a mistake. 
the point we need to focus on in the code : after comment line =>  "//if item already added to cart.  Change quantity in shopping card"
 My Shopping card ss and var_dump["Session"] is here. 
My Codes is here
The first method I try is:
//Check if cart is not empty. 
if(isset($_SESSION["cart"]))
{
    $item_array_id = array_column($_SESSION["cart"], "product_id");

    //Check if the same items not added to cart. 
    if(!in_array($_GET["id"], $item_array_id))
    {

        $item_array = array(
            'product_id' => $_GET["id"],
            'item_name' => $_POST["hidden_name"],
            'product_price' => $_POST["hidden_price"],
            'item_quantity' => $_POST["quantity"]
        );
        $_SESSION["cart"][$count] = $item_array;
        echo '<script>alert("Ürün sepete eklendi. ")</script>';
        echo '<script>window.location="product.php"</script>';
    }

    //If item already added to cart change quantity in shopping cart
    else
    {   
        $cnt=0;
        foreach($_SESSION["cart"] as $keys => $values){

            if($values["product_id"]==$_GET["id"]){
                $yeni= $values["item_quantity"]+$_POST["quantity"];
                echo $yeni;
                $item_array = array(
                    'product_id' => $_GET["id"],
                    'item_name' => $_POST["hidden_name"],
                    'product_price' => $_POST["hidden_price"],
                    'item_quantity' => $_POST["quantity"]
                );
                $_SESSION["cart"][$cnt] = $item_array;
            }
            $cnt++;
        }

        echo '<script>alert("Product updated in shoping cart")</script>';
        echo '<script>window.location="product.php"</script>';

    }
}

//if cart is empty.  Create SESSION["cart"]
else
{
    $item_array = array(
        'product_id' => $_GET["id"],
        'item_name' => $_POST["hidden_name"],
        'product_price' => $_POST["hidden_price"],
        'item_quantity' => $_POST["quantity"]
    );
    $_SESSION["cart"][0] = $item_array;
    echo '<script>alert("Ürün sepetinize eklendi. ")</script>';
    echo '<script>window.location="product.php"</script>';
}

The second method I try is:
   //Check if cart is not empty. 
  if(isset($_SESSION["cart"]))
  {
    $item_array_id = array_column($_SESSION["cart"], "product_id");

    //Check if the same items not added to cart. 
    if(!in_array($_GET["id"], $item_array_id))
    {

        $item_array = array(
        'product_id' => $_GET["id"],
        'item_name' => $_POST["hidden_name"],
        'product_price' => $_POST["hidden_price"],
        'item_quantity' => $_POST["quantity"]
        );
        $_SESSION["cart"][$count] = $item_array;
        echo '<script>alert("Ürün sepete eklendi. ")</script>';
        echo '<script>window.location="product.php"</script>';
    }

    //If item already added to cart change quantity in shopping cart
    else
    {   
        $cnt=0;
        foreach($_SESSION["cart"] as $keys => $values){

            if($values["product_id"]==$_GET["id"]){

                $_SESSION["cart"][$cnt][$values]=$values["item_quantity"]+$_POST["quantity"];
            }
            $cnt++;
        }

        echo '<script>alert("Ürün güncellendi. ")</script>';
        echo '<script>window.location="product.php"</script>';
    }
}

//If cart is empty create SESSION["cart"]
else
{
    $item_array = array(
    'product_id' => $_GET["id"],
    'item_name' => $_POST["hidden_name"],
    'product_price' => $_POST["hidden_price"],
    'item_quantity' => $_POST["quantity"]
    );
    $_SESSION["cart"][0] = $item_array;
    echo '<script>alert("Ürün sepetinize eklendi. ")</script>';
    echo '<script>window.location="product.php"</script>';
}

Both methods do not change the amount of the product available.  can you help me with this ? 

A:

Try this:
$_SESSION["cart"][$cnt]['item_quantity'] += $_POST['quantity']

