fetch_assoc()) { $quantest = $rowq['quan']; } if (is_array($cart)) { $cartnum = count($cart); } else { $cartnum = 0; } $added = 0; if ($cartnum > 0) { $cartkeys = array_keys($cart); sort($cartkeys); $j = 0; while ($j < $cartnum) { $key = $cartkeys[$j]; $typequery = mysqli_query($conn,"SELECT type FROM store_items WHERE id = $item"); while ($rowt = $typequery->fetch_assoc()) { $type = $rowt['type']; } if ($key == $item AND $type != 'pot') { $oldquan = $cart[$key]; $newquan = $oldquan + $quantity; if ($newquan > $quantest) { $newquan = $quantest; } if ($quantest > 0) { $cart[$key] = "$newquan"; $added = 1; } else { unset($cart[$key]); } } $j++; } if ($added != 1) { $cart[$item] = $quantity; } } else { if ($quantest > 0) { if ($quantity > $quantest) { $quantity = $quantest; } $cart[$item] = $quantity; } } $crt = serialize($cart); $hour = time() + 60*60*24*10; setcookie(cart, $crt, $hour, '/'); //if (isset($_POST['add'])) { } if (isset($_POST['submit'])) { if (is_array($cart)) { $cartnum = count($cart); } else { $cartnum = 0; } if ($cartnum > 0) { $cartkeys = array_keys($cart); sort($cartkeys); $j = 0; while ($j < $cartnum) { $key = $cartkeys[$j]; $delete = $_POST['item_delete_'.$key]; if ($delete == 1) { unset($cart[$key]); } else { $newquan = $_POST['item_quantity_'.$key]; $quanquery2 = mysqli_query($conn,"SELECT quan FROM store_items WHERE id = '$key'"); while ($rowq2 = $quanquery2->fetch_assoc()) { $quantest = $rowq2['quan']; } if ($newquan == 0 OR $quantest < 1) { unset($cart[$key]); } else { if ($newquan > $quantest) { $newquan = $quantest; } $cart[$key] = $newquan; } } $j++; } $crt = serialize($cart); $hour = time() + 60*60*24*10; setcookie(cart, $crt, $hour, '/'); //if ($cartnum > 0) { } //if (isset($_POST['submit'])) { } if (is_array($cart)) { $cartnum = count($cart); } else { $cartnum = 0; } if ($cartnum > 0) { $cartkeys = array_keys($cart); sort($cartkeys); $j = 0; while ($j < $cartnum) { $key = $cartkeys[$j]; $orderquery = mysqli_query($conn,"SELECT price,ship FROM store_items WHERE id ='$key'"); while ($rowo = $orderquery->fetch_assoc()) { $price = $rowo['price']; $ship = $rowo['ship']; } if ($ship == "Y") { $shipquery = mysqli_query($conn,"SELECT price FROM store_shipping WHERE id = '1'"); while ($rows = $shipquery->fetch_assoc()) { $newshipprice = $rows['price']; } $shipprice = $shipprice + $newshipprice; } $sub = ($cart[$key] * $price); $total = $total + $sub; $shipprice = number_format($shipprice,2,'.',''); $total = number_format($total,2,'.',''); $j++; } } setcookie(total, $total, $hour, '/'); setcookie(shipprice, $shipprice, $hour, '/'); $total = ''; $sub = ''; $shipprice = ''; ?> Shopping Cart - Crocker Farm Stoneware Auction
Cart
0) { echo "
"; } if ($guest != 1) { $userquery = mysqli_query($conn,"SELECT firstname,lastname,city,state FROM users WHERE username = '$username'"); while ($rowu = $userquery->fetch_assoc()) { $firstname = $rowu['firstname']; $lastname = $rowu['lastname']; $city = $rowu['city']; $state = $rowu['state']; } //echo "

$firstname $lastname
$city, $state


"; } if ($cartnum > 0) { if ($shipping == 1) { $shipprice = number_format($shipprice,2,'.',''); } else { $shipprice = "0.00"; } $grandtotal = $total + $shipprice; echo "

"; if ($state == "MD") { $tax = $total * .06; $tax = number_format($tax,2,'.',''); //echo "

6% MD Sales Tax: $$tax

"; $grandtotal = $grandtotal + $tax; } if ($state == "PA") { $tax = $total * .06; $tax = number_format($tax,2,'.',''); //echo "

6% PA Sales Tax: $$tax

"; $grandtotal = $grandtotal + $tax; } $grandtotal = number_format($grandtotal,2,'.',''); //THIS makes $guest = 0 just to reset everything if we come back to this page as a logged-in person; not positive that this is needed--haven't tested it $guest = 0; } echo "
"; if ($oops != '') { echo "
"; echo ""; $oops = unserialize($oops); $oopsnum = count($oops); $oi = 0; if ($oopsnum == 1) { echo "One"; } else { echo "Some"; } echo " of your items "; if ($oopsnum == 1) { echo "is"; } else { echo "are"; } echo " now Out of Stock:

"; for ($oi = 0;$oi < $oopsnum;$oi++){ $oopsid = $oops[$oi]; $oopstitlequery = mysqli_query($conn,"SELECT title FROM store_items WHERE id = $oopsid"); while ($rowoops = $oopstitlequery->fetch_assoc()) { $oopstitle = $rowoops['title']; } echo "• $oopstitle"; if ($oi < $oopsnum - 1) { echo "
"; } } echo "

How Did This Happen? If an item is low in stock or one-of-a-kind, someone else purchased the last one between the time you added it to your cart and when you actually tried to pay for it."; echo "


"; unset($_SESSION['oops']); } if (is_array($cart)) { $cartnum = count($cart); } else { $cartnum = 0; } if ($cartnum > 0) { $cartkeys = array_keys($cart); sort($cartkeys); $j = 0; while ($j < $cartnum) { $key = $cartkeys[$j]; $orderquery2 = mysqli_query($conn,"SELECT id,title,price,ship,type FROM store_items WHERE id ='$key'"); while ($rowo2 = $orderquery2->fetch_assoc()) { $id = $rowo2['id']; $title = $rowo2['title']; $price = $rowo2['price']; $ship = $rowo2['ship']; $type = $rowo2['type']; if ($ship == "Y") { $shipping = 1; $shipquery = mysqli_query($conn,"SELECT price FROM store_shipping WHERE id = '1'"); while ($rowship = $shipquery->fetch_assoc()) { $newshipprice = $rowship['price']; } $shipprice = $shipprice + $newshipprice; } $photoquery = mysqli_query($conn,"SELECT photo_tag,file_num FROM store_photos WHERE item_id='$key' ORDER BY rank, file_num LIMIT 1"); while ($rowph = $photoquery->fetch_assoc()) { $phototag = $rowph['photo_tag']; $photonum = $rowph['file_num']; } $filename = "$phototag.$photonum"; $size = GetImageSize( "../store/images/tb_".$filename ); $width = ceil($size[0] / 2); $width = $width.'px'; $height = ceil($size[1] / 2); $height = $height.'px'; echo "
"; } else { echo "catrowcream\">"; } echo "
"; echo "
"; echo "
$title
"; echo "
$$price
"; $sub = ($cart[$key] * $price); $total = $total + $sub; echo "
"; echo "
"; if ($cartnum - $j == 1) { echo "
"; } echo "
"; echo "
"; if ($cartnum - $j > 1) { echo "
"; } $count++; $catrow++; } $j++; } $totalformatted = number_format($total,2,'.',''); echo "
Subtotal: $$totalformatted
"; //ends if cartnum > 0 -> I THINK!?!?!? } else { echo "

There Are No Items In Your Cart.

"; } echo "

<< Back to Store

"; ?>
0) { echo "
"; echo "
"; echo "
"; echo "
"; echo ""; echo "$design_footer"; //if pass == info or username == guest ???? } else //if the cookie does not exist, they are taken to the login screen { header("Location: ../guest/"); } ?>