I’m trying to add submit buttons and hidden input fields so that when a user clicks a submit button I can identify the item they selected. Although I can’t figure out how to access the hidden values. I have this code (the value in input type=”hidden” are the item’s id’s). How do I access the values?
foreach($dbh->query("SELECT * FROM beer WHERE country_id = $countryID") as $beer) {
echo "<a href='BeerSummary.php?beerID=$beer[id]'>$beer[2]</a> <br/>";
echo "ABV $beer[3]% - $beer[4] ml - Case Size $beer[5] - Price £$beer[6]";
echo '<input type="submit" value="Add to Cart"> <br/>';
echo '<input type="hidden" name="beer_id[]" value="'.$beer[0].'">';
echo "<br/>";
}
if(isset($_POST["beer_id"])) {
//
}
You have them defined as an input array, so the way to access it/them would be: