Its not just a variable, the situation's like this:
mysql_connect("localhost", "root", "") or die (mysql_error ());
mysql_select_db("tHofbrouwerijke") or die(mysql_error());
$strSQL = "SELECT * FROM bieren";
$rs = mysql_query($strSQL);
while($row = mysql_fetch_array($rs))
{echo "<form action='RemoveBier.php' method='POST'><button type='submit' name=".$row['Naam'].">Verwijderen</button>    ".$row['Naam']."<br>";}
echo "</form>";
?>
so I used a while loop to get items from a database, and I want to use the name of the button to identify which item I have to delete. When I go to the page 'RemoveBier.php' and type in the code i think is right and try it, it does nothing. My second php page looks like this:
<?php
include 'DeleteBier.php';
$NameButton=$row['Naam'];
mysql_connect("localhost", "root", "") or die (mysql_error ());
mysql_select_db("tHofbrouwerijke") or die(mysql_error());
echo $row['Naam'];
$strSQL = "DELETE FROM bieren WHERE naam = '.$_POST[$NameButton].'";
mysql_query($strSQL) or die(mysql_error());
header('Location: DeleteBier.php');
?>
<form method="post">
<input type="hidden" name="Beer2delete" value="SOME BEERS NAME HERE" />
<button>Submit</button>
</form>
You now have access to the name with $_POST['Beer2delete']
. Users wont see it and you have a consistent name to refer to.
if you have multiple options, you can do it this way:
<form method="post">
<!-- HERE YOU LOOP, but the radiobutton so it will result in the following -->
<input type="radio" name="beer2delete" value="beer 1" /> Beer 1 <br />
<input type="radio" name="beer2delete" value="beer 2" /> Beer 2 <br />
<input type="radio" name="beer2delete" value="beer 3" /> Beer 3 <br />
<input type="radio" name="beer2delete" value="beer 4" /> Beer 4 <br />
<input type="submit" name="DeleteBeer" value="Delete that delicious beer"/>
</form>