It looks like you are trying to add to cart from the recordset, but the recordset code is below the add to cart code. The solution is probably to move the add to cart code lower on the page.
Try moving the code on lines:16-52 down below the recordset code that ends on line 161.