At a glance, I think you are looping too much of the script (and to be honest, you should be using a for loop, not a while), and you have a form nested inside a form, which isn't valid and won't work.
it looks to me like you want a basic form that asks for quantity, and when that is submitted, you want to redisplay it, but also display a number of forms equal to the quantity to collect information on each instance? and i assume when that is submitted you are done with collection?