I suspect the problem you are having has to do with the conditional creation of form elements. For the first 3 deli products you create the 5 elements (dept, qty1, qty2, qty3, basket). The bakery product only creates 3 of those (all but qty2 and qty3). So in the end the array length for qty1 is different from qty2 and qty3.
Consider just the quantity fields. Here's a table of the array indexes for each of the resulting values of those fields for each product:
Code:
|- Indexes --|
Item qty1 qty2 qty3
Deli1 0 0 0
Deli2 1 1 1
Deli3 2 2 2
Bakery1 3 - -
Deli4 4 3 3
So when you loop thru the items and you get to deli item 4, you try to get qty2 field index 4 which doesn't exist, thus the out of range error.
The solution to this problem is to always draw out all possible fields for a product regardless if you actually need to use them. In the case of a bakery product you don't need to use the qty2 and qty3 fields, but it does no harm to have them there because you can just ignore them. But more importantly, they are required to keep your arrays in sync.
Peter
------------------------------------------------------
Work smarter, not harder.