它不仅仅是一个变量,情况是这样的:
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>";
?>
所以我使用了while循环从数据库中获取项目,我想使用按钮的名称来标识我必须删除的项目。当我进入“RemoveBier.php”页面并输入我认为正确的代码并尝试它时,它什么也没做。我的第二个php页面如下所示:
<?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');
?>
答案 0 :(得分:0)
<form method="post">
<input type="hidden" name="Beer2delete" value="SOME BEERS NAME HERE" />
<button>Submit</button>
</form>
您现在可以使用$_POST['Beer2delete']
访问该名称。用户不会看到它,并且您有一致的名称可供参考。
如果您有多个选项,可以这样做:
<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>