whileループ内でデータベースレコードを削除しようとしています。 whileループを使用してユーザーリストをテーブルに表示しています。私はボタンを持って、ブートストラップモーダルはモーダルウィンドウを開きます。そのウィンドウで私は削除ボタンに提出している。 whileループ。 問題は、このレコードを削除しようとしていますが、そのレコードを削除しています。あなたは問題があることを確認できますか?whileループ内のクエリを削除する
ありがとうございました。
<table class="table table-hover">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Surname</th>
<th>Email</th>
<th>Password</th>
<th>*</th>
</tr>
</thead>
<tbody>
<?php
$q = "SELECT * FROM users";
$r = mysqli_query($dbc,$q);
while($list = mysqli_fetch_assoc($r)){
if(isset($_POST['del_submit'])){
$q = "DELETE FROM users WHERE id = '$list[id]' ";
$r = mysqli_query($dbc, $q);
header('Location: index.php?page=7');
}
echo '<tr>';
echo '<td>'.$list['id'].'</td>';
echo '<td>'.$list['name'].'</td>';
echo '<td>'.$list['surname'].'</td>';
echo '<td>'.$list['email'].'</td>';
echo '<td>'.$list['password'].'</td>';
echo '<td><button class="btn btn-danger btn-xs" data-toggle="modal" data-target=".delete'.$list['id'].'"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button> ';
echo '</tr><form method="post" action="#">';
echo '<div class="modal fade delete'.$list['id'].'">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Delete <strong class="text-primary">'.$list['name'].' ?</strong></h4>
</div>
<div class="modal-body">
<strong class="text-primary">'.$list['name'].' '.$list['surname'].'</strong><br>
Are you Sure?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" name="del_submit" id="del_submit" class="btn btn-danger"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete</button>
</div>
</div>
</div>
</div></form>';
}
?>
</tbody>
</table>
になり、あなたのエラーログを確認しましたか?クエリが機能していると仮定しています。 あなたのファイルの先頭にエラー報告を追加するのは、あなたのファイルの最初の '<?php'タグ' error_reporting(E_ALL);の直後です。 ini_set( 'display_errors'、1); ' –
最後のレコードを削除するかどうか選択ループに項目を削除するのは奇妙です。 '$ list ['id']'のようなナンセンスではなく、 'id =(int)$ _ POST ['id']'という条件を使ってレコードを削除します。 – panther
リスト内の最初のIDを削除します。たとえば、最初のid = 1秒= 2 ... 4:4 :たとえば、3番目の削除ボタンをクリックすると、その最初のレコードが削除されます。 –