Jump to content

Warning: Cannot Modify Header Information - Headers Already Sent


smallc28

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/

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.