从表中获取值后,我尝试使用模式删除数据库用户。但我认为价值无法带到php。
这是我获取模态ID的地方
<button type="button" class="my-1 mr-1 btn btn-danger fas fa-trash-alt user-delete" data-toggle="modal" data-target="#buttonDelete" data-id="<?php echo $id ?>"></button>
这是发送它的js
const deleteButtons = document.getElementsByClassName('user-delete');
const userid2 = document.getElementById('user-id-2');
for (let button of deleteButtons) {
button.addEventListener('click', () => {
userid2.value = button.dataset.id
})
}
这是模态,我必须在单击该用户后将其删除,但它不起作用
<div class="modal fade" id="buttonDelete" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Hapus?</h5>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">Anda akan menghapus user ini</div>
<div class="modal-footer">
<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
<?php $delquery = "DELETE FROM user WHERE id='$id'"; ?>
<form class="" method="post">
<input id="user-id-2" class="form-control-plaintext" type="text" name="id_product" value="<?php $id ?>">
<button class="btn btn-primary" onclick="<?php $connection->query($query) ?>" type="submit">Hapus</button>
</div>
</div>
</div>
</div>
请帮助我,有没有一种方法可以使它有效或更好的方法。谢谢