我正在使用 SQL 语句学习 PHP,但在尝试创建删除按钮时遇到了问题。
问题是当我按下“删除”按钮时什么都没有发生。查询运行正常,它从循环中获取正确的用户 ID。
<?php
require_once 'db_connect.php';
$select = "SELECT * FROM Users";
$result = mysqli_query($dbc, $select) or die('could not query database');
while ($row = mysqli_fetch_assoc($result)) {
echo '
<tr>
<td>' . $row['userid'] . '</td>
<td>' . $row['fnamn'] . ' ' . $row['enamn'] . '</td>
<td>' . $row['username'] . '</td>
<td>' . $row['email'] . '</td>
<td>' . '<form action="" method="post">
<input type="button" name="delete" value="Radera" />
</form>' . '</td>
</tr>';
if(isset($_POST['delete'])) {
$userid = $row['userid'];
$delete = "DELETE FROM Users WHERE userid = '$userid' ";
$result = mysqli_query($dbc, $delete) or die('could not query database');
}
}
mysqli_close($dbc);
?>