我的目标是显示整个表格,例如 SELECT * FROM 运动员并在表格输出中包含每一行的按钮,按下该按钮时将从数据库中删除该行。
我关注了另一篇文章,下面显示的是我到目前为止但不起作用的内容:
//if(isset($_POST['delete_id']) && (!empty($_POST['delete_id'])))
if(isset($_POST['Delete'])){
$delete_id = mysql_real_escape_string($_POST['delete_id']);
echo("deletebutton" . $delete_id);
//mysql_query("DELETE FROM KeepScores WHERE `id`=".$delete_id);
//header('Location: main.php');
}
else
{
$query = 'SELECT * FROM athlete';
$result = mysql_query($query);
$self = $_SERVER['PHP_SELF'];
$self = htmlentities($_SERVER['PHP_SELF']); // strip tags to improve security
echo("<table>
<tr>
<td> id </td>
<td>last name</td>
<td>first name</td>
<td>delete data</td>
</tr>");
while($row = mysql_fetch_array($result))
{
$id = $row['id'];
echo("<tr>");
echo("<td>" . $row['id'] . "</td>");
echo("<td>" . $row['lastName'] . "</td>");
echo("<td>" . $row['firstName'] . "</td>");
echo("<td> <form action='$self' method='post'>
<input type='hidden' name='delete_id value='$id' />
<input type='submit' value='Delete' />
</form>
</td>
</tr>");
}
mysql_free_result($result);
echo("</table>");
}
但是,这不起作用。有谁知道为什么。注意:我没有留下我的登录凭据,但我正在连接到文件中其他地方的数据库。