The title is probably confusing, but here is what I am trying to do and failing miserably at:
I want to display all the items from my db table named 'inventory'.
Then, a user would select one item by clicking a 'Add to cart' image button.
When the button is clicked, the form is submitted to "addtocart.php" for processing the item selected and gets directed back to the inventory page.
Now that you know what i'm trying to do, here is where I am stuck:
I have all the items displayed in a table.
The query is "Select * from pantry", and then I display it like this:
while($pantry = mysql_fetch_assoc($sql))
{
echo "<tr><td>" . $pantry . "</td><td>" . $pantry . "<input type=hidden name=item value='".$pantry."'><input type=image class=addcart></td></tr>";
}
so far, so good, it displays each item and the add to cart submit button.
The problem is, when it gets processed by "addtocart.php", it only recognizes the very last item displayed. What I mean is, if I add item A to my cart and hit submit, "addtocart.php" will add item Z to the database. Item Z is the very last item that is displayed on the page, and is what gets inserted to the db no matter what item I actually selected.
I guess the problem is in my while loop some where. The purpose of the hidden input is supposed to be to assign the item's name to the form variable, but as I said, each item is not getting assigned their own unique name, they are all assigned "item Z"!
What am I doing wrong?