All items have been removed from your cart.");
}
if ($_GET[Action] == "add"){
if (!empty($_GET[ItemID])){
$result = safe_query("SELECT * FROM item WHERE id=$_GET[ItemID]");
$row = mysql_fetch_assoc($result);
if (!empty($row[id])){
safe_query("DELETE FROM cart WHERE date_placed<='" . date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")-2, date("Y"))) . "'");
$result = safe_query("SELECT * FROM cart WHERE user_name='$user_name'");
$foundItFlag = FALSE;
while ($row2 = mysql_fetch_assoc($result)) {
if ($row2[item_id] == $row[id]){
$itemQuantity = $row2[item_quantity] + 1;
safe_query("UPDATE cart SET item_quantity=$itemQuantity WHERE id=$row2[id]");
$foundItFlag = TRUE;
}
}
if (!$foundItFlag){
safe_query("INSERT INTO cart (user_name, item_id, item_quantity, date_placed) VALUES ('$user_name', $_GET[ItemID], 1, '" . date("Y-m-d") . "')");
}
echo ("
Item was successfully added to your cart.");
}
}
}
if ($_GET[Action] == "update"){
if (!empty($_POST[items]) && !empty($_POST[new_quantity])){
$item_list = $_POST[items];
$quantity_list = $_POST[new_quantity];
safe_query("DELETE FROM cart WHERE user_name='$user_name'");
$count = 0;
foreach ($item_list as $item) {
if ($quantity_list[$count] != "0"){
safe_query("INSERT INTO cart (user_name, item_id, item_quantity, date_placed) VALUES ('$user_name', $item, $quantity_list[$count], '" . date("Y-m-d") . "')");
}
$count++;
}
echo ("
Your cart has been updated.");
}
}
?>
Shopping Cart
Please verify the contents of your cart and then click "Pay Now".