Jump to content

Recommended Posts

I need some a little help can't seem to find my own error ....What I'm trying to go for is a size select drownbox so when someone select Small,Medium or Large from Form1 that selection then gets pushed into my Cart Array along with my items id and quantity but for some reason I keep getting

 

Notice: Undefined variable: sizeList in /home/content/72/10029872/html/cart.php on line 21

 

Warning: Cannot modify header information - headers already sent by (output started at /home/content/72/10029872/html/cart.php:21) in /home/content/72/10029872/html/cart.php on line 38 array

 

<!------- HTML FORM --------->

<form id="form1" name="form1" method="post" action="cart.php">

<select name="size">

<option value="1">Small</option>

<option value="2">Medium</option>

<option value="3">Large</option>

input type="hidden" name="pid" id="pid" value="<?php echo $sizeList; ?>" />

</select>

<input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" />

<input type="submit" name="button" id="button" value="Add to Shopping Bag" />

</form>

<!------- PHP CART ARRAY ------->

<?php

if (isset($_POST['pid'])) {

$pid = $_POST['pid'];

$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" => 1, "size" => $sizeList));

} 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 foreach loop

if ($wasFound == false) {

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

}

}

header("location: cart.php");

exit();

}

?>

When posting code, enclose it within the forum's'

 . . . 

BBCode tags.

 

For your header problem, read this first: http://forums.phpfreaks.com/topic/1895-header-errors-read-here-before-posting-them/

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.