我不知道我的代码有什么问题,但我有这个错误注意:未定义索引:删除
我想用 CRUD 做删除功能
这是我的 php 代码:
if($_POST["delete"])
{
$query = '
DELETE FROM `users` WHERE id = :id
';
$statement = $connect->prepare($query);
$statement->execute(
array(
':id' => $_POST['id']
)
);
$result = $statement->fetchAll();
if(isset($result))
{
echo '<div class="alert alert-fill-danger" role="alert">User Deleted!<div>';
}
}
这是 AJAX 函数
$(document).on('click', '#delete', function(){
var id = $(this).data('id');
$('#message').html('');
Swal.fire({
title: 'Are you sure?',
text: "You want to delete this user?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes'
}).then((result) => {
if (result.value){
$.ajax({
url:'/auth/action',
method:'POST',
data:{id:id},
success:function(data)
{
if(data != '')
{
load_user_data();
$('#message').html(data);
}
}
});
Swal.fire(
'User Deleted!',
'',
'success'
)
}
})
});
我不知道我在这里错过了什么,但是 php 中的功能不起作用??
Helenr
holdtom