链接 html 按钮单击


Linking html button click

$result = mysql_query('SELECT * FROM teams');
while($row = mysql_fetch_array($result))
{
  $team= $row['team'];
  $goals= $row['goals'];
  $squadsize= $row['squadsize'];
  $league= getTheirLeague($team);
  echo $team. "</br>";
  echo "Goals Scored " . $goals. "</br>";
  echo "League " . $league. "</br>" . "</br>";
  <form method="POST" action="football.php">
    <button type="button">Edit</button>
    <button type="button">Remove</button>
  </form>
}

正在尝试为我的团队添加删除和编辑功能,对于我打印的每个团队,我都有一个带有 2 个按钮的表单。我不确定的是如何将按钮点击与按钮所属的最终团队联系起来。

由于每一行(团队(都有自己的形式,只需添加一个带有团队标识符的隐藏字段(假设本例中为 $row['team'](。

请注意,IE在表单中具有糟糕的<button>支持。我建议使用提交输入...

<form method="POST" action="football.php">
    <input type="hidden" name="team"
        value="<?php echo htmlspecialchars($row['team']) ?>">
    <input type="submit" name="edit" value="Edit">
    <input type="submit" name="remove" value="Remove">
</form>

然后,您可以通过检查$_POST['team']来判断哪个团队表单是提交的,以及使用哪个按钮按下了...

if (isset($_POST['edit']) { 
    // edit clicked
}
if (isset($_POST['remove']) {
    // remove clicked
}