PHP checking submit with if and else statements?

Thomas

New member
I have received data from my MySQL Database, and I made a while loop so it puts all the products I have on my page. I made this code to check to see if somebody clicks add to cart on the product.

while ($row1 = mysql_fetch_assoc($result1)) {
extract($row1);
{
<form action="search.php" method="post">
<input type='submit' name='$name' value='Add to Cart' />
</form>

if ($_POST['$name'] == "Add to Cart") {
echo "test";
}
}
}

This doesn't seem to work. However, if I do this it works, but it is not what I want.

while ($row1 = mysql_fetch_assoc($result1)) {
extract($row1);
{
<form action="search.php" method="post">
<input type='submit' name='addToCart' value='$name'' />
</form>

if ($_POST['addToCart'] == "$name") {
echo "test";
}
}
}

I need help getting to make it so that it works with the $name as the name of the submit button.

Thanks
 
Back
Top