0

How do i go of the error listed below in my php cart page

Warning: Invalid argument supplied for foreach() in

Undefined variable: wasFound in

Notice: Undefined variable: wap in

Warning: array_push() expects parameter 1 to be array, null given in

page:

<?php 
    session_start(); // Start 
    include "storescripts/connect_to_mysql.php"; 
    session_start(); // Start 
    if (isset($_POST['pid'])) {
        $pid = $_POST['pid'];
        if (isset($_POST['quanity'])) {
            $wap = $_POST['quanity'];
        }
        $wasFound = 'false';
        $i = '0';
        // If the cart session variable is not set or cart array is empty
        if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { 
            // RUN IF THE CART IS EMPTY OR NOT SET
            $_SESSION["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => $wap));
       } else {
            // RUN IF THE CART HAS AT LEAST ONE ITEM IN IT
            foreach ($_SESSION["cart_array"] as $each_item) { 
                $i++;
                while (list($key, $value) = each($each_item)) {
                    if ($key == "item_id" && $value == $pid) {
                        // That item is in cart already so let's adjust its quantity using array_splice()
                        array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1)));
                        $wasFound = true;
                    } // close if condition
                } // close while loop
            } // close while loop
            if ($wasFound == false) {
                array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => $wap));
            }
        }
        header("location: cart.php"); 
        exit();
    }
    ?>

thanks for impact

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149

0 Answers0