Substantial Deviations from Amazing Stuff: The quantity is selected as the user adds items to their cart, and not in the shopping cart itself. An order will fail (for just that item) if there is an invalid number of items in the shopping cart AT TIME OF CHECKOUT. One possible way taht this can happen is another user buys all of the requested item and checks out first. The inventory is not decremented until the items are checked out. Merely adding the items to the cart does not lower the displayed stock. This was mainly done to prevent "cart-squatting", where a user could fill the cart with items they have no intention of purchasing in order to sabotage the website. The SQL should be set up in such a way as to make "orphan orders" impossible. The orders table has a triple primary key, that being the customerID (FK), productID, and a timestamp. This timestamp only exists to allow customers to buy an item once, and later come back and add the same item. If the customer removes the last item from their order, there is no combination of that customerID/item pair for which an order is in progress. That's how the shopping cart works, it looks at all in-progress orders from the logged-in customer.