http://webdesign.nfshost.com/TShirts/ - here is where you can test the cart out (add/delete tqtqtq & afafa with various sizing options)
Try adding/deleting items for a while and watch the anomalies... size options for afafa will transfer over to tqtqtq's session variable... sometimes it may seem like its working for a while, but keep trying and it will screw up... Also, when you delete an item from the cart, sometimes the other item's size options will disappear. They will even reappear sometimes if I'm not mistaken.
Thanks
Code: Select all
<?php
session_start();
$action=$_GET['action'];
$rem=$_GET['rem'];
$cart = $_SESSION['cart'];
if ($action == 'add_item'){
$itemsize=$_POST['options'];
$cart = $_SESSION['cart'];
if ($cart!='' && $cart!=' ') {
$cart .= ','.$_GET['id'];
} else {
$cart = $_GET['id'];
}
$_SESSION['cart'] = $cart;
}
if ($rem=='del'){
$id=$_GET['id'];
$eggyolkB='count-'.$id;
$thec=$_SESSION[$eggyolkB];
$finale='rowopt'.$thec;
$_SESSION[$finale]='';
if ($cart==$id){
$cart='';
$_SESSION['cart'] = $cart;
}
if ($cart) {
$items = explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
$cart = $newcart;
}
}
if ($action == 'update'){
if ($cart) {
$newcart = '';
foreach ($_POST as $key=>$value) {
if (stristr($key,'qty')) {
$id = str_replace('qty','',$key);
$lenlen = strlen($value);
if ($lenlen!=0 && strspn($value,"1234567890")!=$lenlen){
$death='death';
}
}
}
if ($death!='death'){
foreach ($_POST as $key=>$value) {
if (stristr($key,'qty')) {
$id = str_replace('qty','',$key);
$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart != '') {
$newcart .= ','.$id;
} else {
$newcart = $id;
}
}
}
}
$cart = $newcart;
}
}
}
if ($death!='death'){
$_SESSION['cart'] = $cart;
$column==1;
$items = explode(',',$cart,100);
//array of all items in cart
$_SESSION[num_items] =count($items);
$inlist = implode(", ",$items);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$_SESSION[unique_items] =count($contents);
$vivian=1;
if($_SESSION[cart] != ''){
$db = 'XXXXXX.db';
$user = 'XXXXXX';
$pass = 'XXXXXX';
$db2 = 'items';
$table = 'items';
$select = '*';
$con = mysql_connect($db, $user, $pass) or die(mysql_error());
mysql_select_db($db2) or die(mysql_error());
$query = "SELECT $select FROM $table WHERE id IN ($inlist)";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$beeb=$row[image75];
$_SESSION[rowMT.$vivian]=$beeb;
$p=$row[id];
$_SESSION[rowid.$vivian]=$p;
$caddy=$row[cat1];
$caddylnk=explode(' - ',$caddy,100);
$cc1=$caddylnk[0];
$cc2=$caddylnk[1];
$_SESSION[rowlnk.$vivian]= $_SESSION[backbutton].'?id='.$p;
$ebbe=$row[name];
$_SESSION[rowname.$vivian]=$ebbe;
$q=$contents[$p];
$_SESSION[rowquant.$vivian]=$q;
$c=$row['price'];
$_SESSION[rowprice.$vivian]=$c;
$_SESSION[rowsum.$vivian] =($c*$q);
$tippity=$_GET['id'];
if ($tippity==$p && isset($itemsize)){
if (empty($_SESSION[rowopt.$vivian]) || $_SESSION[rowopt.$vivian]==''){
$boz='skaggs';
} else {
$boz='';
}
if ($boz != 'skaggs'){
$_SESSION[rowopt.$vivian]=$_SESSION[rowopt.$vivian].', '.$itemsize;
} else if ($boz=='skaggs') {
$_SESSION[rowopt.$vivian]=$itemsize;
}
}
$vivian++;
}
$ttt=1;
$additives = array();
while ( $ttt <= $_SESSION[unique_items] ){
$additives[$ttt] = $_SESSION[rowsum.$ttt];
$ttt++;
$_SESSION[total]=array_sum($additives);
}
}else{
$_SESSION[total]=0;
$_SESSION[num_items]=0;
}
if($_SESSION['cart']==''){
$_SESSION[unique_items]=0;
}
$_SESSION['cart'] = $cart;
if (isset($rem) || $action=='update'){
header("location:http://www.JReidyWebDesign.com/shoppingcart");
} else {
$backbackback='http://www.jreidywebdesign.com'.$_SESSION[goback];
if(isset($_SESSION[gobackid])){
$backbackback='http://www.jreidywebdesign.com'.$_SESSION[goback].'?id='.$_SESSION[gobackid];
}
header("location: $backbackback");
}
} else {
header("location:http://www.JReidyWebDesign.com/shoppingcart?qtyerror=23");
}
?>