session - Updating PHP Shopping Card Data via $_SESSION -


i'm having trouble updating product quantity in shopping cart. use array, $productarray, store product_id, product_name, quantity, , product_price database. check if there product product id in $_session. if yes, update quantity, if not, merge $_session.

the issue here i'm not able reach code checks product_id in session variable, hence keeps merging same product shopping cart instead of updating quantity.

my code below. please let me know if there additional components should include post. thanks.

case "add":     if(!empty($_post["qty"])) {         $productbyid = $db_handle->runquery("select * products  product_id= " . $_get["pid"]);  $productarray = array($productbyid[0] ["product_id"]=>array('product_name'=>$productbyid[0]["product_name"], 'product_id'=>$productbyid[0]["product_id"], 'quantity'=>$_post["qty"], 'product_price'=>$productbyid[0]["product_price"]));          if (!empty($_session["cart_item"])) {             if (in_array([$productbyid[0]["product_id"]],$_session["cart_item"])) {                 foreach ($_session["cart_item"] $k => $v) {                     if ($productbyid[0]["product_id"] == $k)                         $_session["cart_item"][$k]["quantity"] = $_post["qty"];                 }             } else {                 $_session["cart_item"] = array_merge($_session["cart_item"],$productarray);             }         } else {             $_session["cart_item"] = $productarray;         }        } 

the statement in_array([$productbyid[0]["product_id"]],$_session["cart_item"]) return false in case.

you should change isset($productbyid[0]["product_id"], $_session["cart_item"]) guest save each product info element key product id inside $_session["cart_item"] array.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -