Hey all,
I'm writing a shopping cart that uses cookies right now and I'm having a few problems. The code below is the first part of the cart, it adds the items and searchs to see if that exact item already exists, then it only updates the quantity. It seems to be working fine.
if ($_GET['submit']) {
$uniqueQuery = "select * from extendedproduct where size = '$fSize' and color = '$fColor' and productid = '{$_GET['prodID']}'";
$uniqueResult = mysql_query($uniqueQuery);
$uniqueRow = mysql_fetch_array($uniqueResult);
$count = count($_COOKIE['cookieUniqueID']);
$count++;
for ($i = 0; $i <= count($_COOKIE['cookieUniqueID']); $i++) {
if ($_COOKIE['cookieUniqueID'][$i] == $uniqueRow['uniqueid']) {
$fQuantity += $_COOKIE['cookieQuantity'][$i];
setcookie("cookieQuantity[$i]", $fQuantity);
$duplicate = true;
}
}
if (!$duplicate) {
setcookie("cookieUniqueID[$count]", $uniqueRow['uniqueid']);
setcookie("cookieQuantity[$count]", $fQuantity);
}
header ("Location: viewproducts.php?cat=$cat");
}
Here is the problem, when you want to delete an item, no matter how many items you have in your cart, it deletes the first item every time. I'm stumped, I can't figure it out... Here is the code to delete an item below.
if ($_GET['delete']) {
$uArray = array_values($_COOKIE['cookieUniqueID']);
$qArray = array_values($_COOKIE['cookieQuantity']);
for ($i = 1; $i <= count($_COOKIE['cookieUniqueID']); $i++) {
setcookie("cookieUniqueID[$i]", "");
setcookie("cookeQuantity[$i]", "");
}
for ($i = 1; $i <= count($uArray); $i++) {
if ($i == $_GET['delete']) {
unset($uArray[$i]);
unset($qArray[$i]);
}
}
$uArray = array_values($uArray);
$qArray = array_values($qArray);
for ($i = 1; $i <= count($uArray); $i++) {
setcookie("cookieUniqueID[$i]", $uArray[$i]);
setcookie("cookeQuantity[$i]", $qArray[$i]);
}
header("Location: viewcart.php");
}
Any help on this would be greatly appreciated!!
insectis