在单击删除按钮后尝试删除行,但是即使没有错误,也行不通。起初,我认为这与if语句有关,但是什么都没有改变……这是我的删除代码!还有其他办法吗?谢谢
<?php
echo "<table>
<caption>Λίστα Χρηστών</caption>
<thead>
<tr>
<th scope='col'>Ιd</th>
<th scope='col'>Χρήστης</th>
<th scope='col'>Διαγραφή</th>
</tr>
</thead>";
$servername = "localhost";
$username = "root";
$password = "";
$db = "aws_chat";
// Create connection
$conn = new mysqli($servername, $username, $password,
$db);
// Check connection
$sql = "SELECT username,email,id FROM users WHERE
user_type='user'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
if (isset($_GET['del'])) {
$del = $_GET['del'];
//SQL query for deletion.
$sql_del = "DELETE * FROM users WHERE id=$del";
}
while($row = $result->fetch_assoc()) {
echo "<tbody>
<tr>
<td>".$row["id"]."</td>
<td>".$row["username"] ."</td>
<td><a href='delete_user.php?del=
{$row['id']}'><input type='button' class='btn_del'
value='Delete'/></td>
</tr>
</tbody>
<tfoot>
</tfoot>";
}
} else {
echo "0 results";
}
echo "</table>";
?>
</center></div>
答案 0 :(得分:-1)
更改
DELETE * FROM users WHERE id=$del
到
DELETE FROM users WHERE id=$del
答案 1 :(得分:-2)
//SQL query for deletion.
$sql_del = "DELETE FROM users WHERE id='".$del."' ";
$conn->query($sql_del); // you missed this line which is required to delete the record from database