我不知道我的代码有什么问题,但是我有此错误注意:未定义的索引:删除
我想使用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中的功能无法正常工作?
答案 0 :(得分:0)
也许尝试以下操作:在PHP中尝试使用变量之前,请测试变量的可用性。另外-将没有记录集,因此<system.serviceModel>
<services>
<service name="WcfService1.Service1">
<endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1"></endpoint>
</service>
将不起作用。
fetchAll
答案 1 :(得分:0)
这是我的问题的答案:D
var action = 'delete';
我只是将这段代码添加到ajax中的ID下
if($_POST["action"] == '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>';
}
}