Hey everyone. Having a problem I was hoping someone could help me with. I am fairly new to php (i’ve done some forms and interactive database work) and can’t seem to get this one right. I am adding a couple options (one at a time since i’m still stuck on the first one) to show up on a cart page (size color etc). I have the variable going between the two pages as I can echo it out on the cart page but for some reason I can’t get it to output what variable they choose; in this instance it’s size. I will put the cart php here and if someone more knowledgeable has a moment to peruse it and point out where my error(s) are I would be so grateful as I have been working on this project 10 months (I have a developmental learning disability) and still don’t have a working final product.
[php]session_start();
error_reporting(E_ALL);
ini_set(‘display_errors’, ‘1’);
include “storescripts/connect_to_mysql.php”;
?>
<?php
if (isset($_POST['pid'])) {
$pid = $_POST['pid'];
$wasFound = false;
$i = 0;
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
$_SESSION["cart_array"] = array(1 => array("item_id" => $pid, "quantity" => 1, "size" => $size));
} else {
foreach ($_SESSION["cart_array"] as $each_item) {
$i++;
while (list($key, $value) = each($each_item)) {
if ($key == "item_id" && $value == $pid) {
array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1, "size" => $size)));
$wasFound = true;
}
}
}
if ($wasFound == false) {
array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => 1, "size" => $size));
}
}
header("location: cart.php");
exit();
}
?>
<?php
if (isset($_GET['cmd']) && $_GET['cmd'] == "emptycart") {
unset($_SESSION["cart_array"]);
}
?>
<?php
$submit = $_POST['submit'];
$size = $_POST['size'];
if (isset($_POST['item_to_adjust']) && $_POST['item_to_adjust'] != "") {
$item_to_adjust = $_POST['item_to_adjust'];
$quantity = $_POST['quantity'];
$quantity = preg_replace('#[^0-9]#i', '', $quantity);
if ($quantity >= 100) { $quantity = 99; }
if ($quantity < 1) { $quantity = 1; }
if ($quantity == "") { $quantity = 1; }
$i = 0;
foreach ($_SESSION["cart_array"] as $each_item) {
$i++;
while (list($key, $value) = each($each_item)) {
if ($key == "item_id" && $value == $item_to_adjust) {
array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $item_to_adjust, "quantity" => $quantity, "size" => $size)));
}
}
}
}
?>
<?php
if (isset($_POST['index_to_remove']) && $_POST['index_to_remove'] != "") {
$key_to_remove = $_POST['index_to_remove'];
if (count($_SESSION["cart_array"]) <= 1) {
unset($_SESSION["cart_array"]);
} else {
unset($_SESSION["cart_array"]["$key_to_remove"]);
sort($_SESSION["cart_array"]);
}
}
?>
<?php
$cartOutput = "";
$cartTotal = "";
$pp_checkout_btn = '';
$product_id_array = '';
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
$cartOutput = "
Your shopping cart is empty
";
} else {
$pp_checkout_btn .= '
';
$i = 0;
foreach ($_SESSION["cart_array"] as $each_item) {
$item_id = $each_item['item_id'];
$sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1");
while ($row = mysql_fetch_array($sql)) {
$product_name = $row["product_name"];
$price = $row["price"];
$details = $row["details"];
$shipping = $row["shipping"];
$pricesub = $price + $shipping;
}
$pricetotal = $pricesub * $each_item['quantity'];
$cartTotal = $pricetotal + $cartTotal;
setlocale(LC_MONETARY, "en_US");
$pricetotal = money_format("%10.2n", $pricetotal);
$x = $i + 1;
$pp_checkout_btn .= '
';
$product_id_array .= "$item_id-".$each_item['quantity'].",";
$cartOutput .= "
";
$cartOutput .= '
' . $product_name . '
| ';
$cartOutput .= '' . $details . ' | ';
$cartOutput .= '' . $size . ' | ';
$cartOutput .= '' . "$shipping" . ' | ';
$cartOutput .= '$' . $price . ' | ';
$cartOutput .= '
| ';
$cartOutput .= '' . $pricetotal . ' | ';
$cartOutput .= ' | ';
$cartOutput .= '
';
$i++;
}
setlocale(LC_MONETARY, "en_US");
$cartTotal = money_format("%10.2n", $cartTotal);
$cartTotal = "
Cart Total : ".$cartTotal." USD
";
$pp_checkout_btn .= '
';
}
[/php]