hey all,
For some reason while trying to use a shopping cart script in IE6 and Opera that works fine in other browsers, it doesn't seem to be accepting the $POST variables to pass on to $SESSION. I think the problem lies in my form_check() function but I'm not sure why. Here's the PHP for that section, and the section that displays the basket (my full code is too long for the forum)
PHP:
<?php
function form_check()
{
// check to see if the form has been submitted
// and which submit button was clicked
// if this is an add operation
// add to already existing quantities in shopping cart
if ($_POST['add'])
{
foreach ($_POST['a_qty'] as $k => $v)
{
// if the value is 0 or negative
// don't bother changing the cart
$kid = explode(':', $k);
// key
$product = $kid[0];
// size
$colour = $kid[1];
// colour
$size = $_POST['a_size'][$k];
// quantity
$quant = $v;
if ($v > 0)
{
$added = 'no';
foreach ($_SESSION['cart'] as $key => $value)
{
$sesh = explode(':', $value);
if ($sesh[0] == $product && $sesh[1] == $colour && $sesh[2] == $size)
{
$_SESSION['cart'][$key] = $product . ':' . $colour . ':' . $size . ':' . $quant;
$added = 'yes';
}
else if ($sesh[0] == $product && $sesh[1] == $colour && $sesh[3] == $quant)
{
$_SESSION['cart'][$key] = $product . ':' . $colour . ':' . $size . ':' . $quant;
$added = 'yes';
}
}
if ($added == 'no')
{
$_SESSION['x']++;
$key = $_SESSION['x'];
$_SESSION['cart'][$key] = $product . ':' . $colour . ':' . $size . ':' . $quant;
}
}
}
}
else if ($_POST['addremote'])
{
foreach ($_POST['ar_qty'] as $k => $v)
{
$quant = $v;
}
foreach ($_POST['ar_size'] as $k => $v)
{
$size = $v;
}
foreach ($_POST['ar_colour'] as $k => $v)
{
$colour = $v;
$product = $k;
}
if ($v > 0)
{
$added = 'no';
foreach ($_SESSION['cart'] as $key => $value)
{
$sesh = explode(':', $value);
if ($sesh[0] == $product && $sesh[1] == $colour && $sesh[2] == $size)
{
$_SESSION['cart'][$key] = $product . ':' . $colour . ':' . $size . ':' . $quant;
$added = 'yes';
}
else if ($sesh[0] == $product && $sesh[1] == $colour && $sesh[3] == $quant)
{
$_SESSION['cart'][$key] = $product . ':' . $colour . ':' . $size . ':' . $quant;
$added = 'yes';
}
}
if ($added == 'no')
{
$_SESSION['x']++;
$key = $_SESSION['x'];
$_SESSION['cart'][$key] = $product . ':' . $colour . ':' . $size . ':' . $quant;
}
}
}
// if this is an update operation
// replace quantities in shopping cart with values entered
else if ($_POST['update'])
{
foreach ($_POST['u_qty'] as $k => $v)
{
$kid = explode(':', $k);
$key = $kid[0];
// key
$product = $kid[1];
// size
$colour = $kid[2];
// colour
$size = $_POST['u_size'][$k];
// quantity
$quant = $v;
// if the value is empty, 0 or negative
// don't bother changing the cart
$value = $product . ':' . $colour . ':' . $size . ':' . $quant;
if ($v != "" && $v >= 0)
{
if ($value != $_SESSION['cart'][$key]);
{
$_SESSION['cart'][$key] = $value;
}
}
}
}
else if ($_POST['checkout'])
{
foreach ($_POST['u_qty'] as $k => $v)
{
$kid = explode(':', $k);
$key = $kid[0];
// key
$product = $kid[1];
// size
$colour = $kid[2];
// colour
$size = $_POST['u_size'][$k];
// quantity
$quant = $v;
// if the value is empty, 0 or negative
// don't bother changing the cart
$value = $product . ':' . $colour . ':' . $size . ':' . $quant;
if ($v != "" && $v >= 0)
{
if ($value != $_SESSION['cart'][$key]);
{
$_SESSION['cart'][$key] = $value;
}
}
}
header( 'Location: checkout.php' ) ;
}
// if this is a clear operation
// reset the session and the cart
// destroy all session data
else if ($_POST['clear'])
{
$_SESSION = array();
session_destroy();
}
}
function display_basket()
{
// initialize a variable to hold total cost
$total = 0;
// check the shopping cart
// if it contains values
// look up the SKUs in the $CATALOG array
// get the cost and calculate subtotals and totals
if (is_array($_SESSION['cart']))
{
foreach ($_SESSION['cart'] as $k => $v)
{
if ($v > 0)
{
$id = explode(':', $v);
// product 0 colour 1 size 2 value 3
echo $id[0] . ':' . $id[1] . ':' . $id[2] . ':' . $id[3];
$query='SELECT pr.prId AS prId, pr.name AS name, pr.price AS price, g.image AS image, c.cId AS cId, c.desc AS colourname, c.colour AS colour FROM products AS pr, colour AS c, productstocolour AS prtoc LEFT JOIN gallery AS g ON g.gId = prtoc.FK_gId WHERE pr.prId = prtoc.FK_prId AND prtoc.FK_cId = c.cId AND pr.prId = ' . $id[0] . ' AND prtoc.FK_cId = ' . $id[1];
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result))
{
echo '<div class="productlist">';
echo '<div class="prodimg">';
if ($row['image'] != '')
{
$image = 'gallery/' . $row['image'];
}
else
{
$image = 'images/noimg.gif';
}
echo '<img src="' . $image . '" alt="' . $row['image'] . '">';
echo '</div>';
echo '<div class="prodtext">';
echo '<h4>' . $row['name'] . '</h4><h5><div style="color:' . $row['colour'] . ';">' . $row['colourname'] . '</div></h5>';
echo 'Price: £' . $row['price'] . ' each <br>Size <select name="u_size[' . $k . ':' . $id[0] . ':' . $id[1] . ']">';
$sizequery = 'SELECT s.sId AS sId, s.size AS size FROM sizes AS s, productstosizes AS prtos WHERE prtos.FK_prId = ' . $row['prId'] . ' AND s.sId = prtos.FK_sId';
$sizeres = mysql_query($sizequery);
while ($srow = mysql_fetch_assoc($sizeres))
{
echo '<option value="' . $srow['sId'] . '"';
if ($srow['sId'] == $id[2])
{
echo ' selected="selected"';
}
echo '>' . $srow['size'] . '</option>';
}
echo '</select> | <label>Quantity: <input type="text" name="u_qty[' . $k . ':' . $id[0] . ':' . $id[1] . ']" id="quantity" size="3" value="' . $id[3] . '" /></label>';
echo '</div>';
echo '</div>';
$subtotal = $row['price'] * $id[3];
$total += $subtotal;
}
}
}
}
return $total;
}
?>
Any ideas?
Cheers
Edd:-)