Deleting data with multiple selections did not work.
one by one I can delete it with a similar code.
but I want to delete multiple records with the checkbox.
index.html
<input type="checkbox" id="checkbox1-1" value="<?php echo $kategori_id; ?>" name="coklu[]">
<button id="btn_del" type="submit" class="btn btn-md btn-danger" data-toggle="tooltip" title="Seçili olanları sil" data-toggle="tooltip" data-placement="right"><i class="fa fa-trash-o"></i> Delete</button>
script code
<script>
$(document).ready(function(){
readProducts();
$(document).on('click', '#btn_del', function(e){
var data = $("#checkbox1-1").serializeArray();
data.is(":checked")
SwalDeletes(data.val());
e.preventDefault();
});
});
function SwalDeletes(data){
swal({
title: 'Emin misiniz?',
text: "Seçilen kategoriler kalıcı olarak silinecek!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Evet',
cancelButtonText: 'İptal',
showLoaderOnConfirm: true,
preConfirms: function() {
return new Promise(function(resolve) {
$.ajax({
url: 'delete.php',
type: 'POST',
data: data,
dataType: 'json'
})
.done(function(response){
swal(responses.titles, responses.message, responses.status);
//readProducts();
})
.fail(function(){
swal(responses.titles, responses.message, responses.status);
//readProducts();
});
});
},
allowOutsideClick: false
});
}
function readProducts(){
$('#load-products').load('index.php');
}
</script>
delete.php
<?php
include_once 'connect.php';
header('Content-type: application/json; charset=UTF-8');
$responses = array();
$secilenler = implode($_POST['data'],', ');
$result = mysqli_query($con, "SELECT * FROM tb_haber_kategori WHERE kategori_id IN ($secilenler)");
while ($row=mysqli_fetch_assoc($result)) {
$coklu_sonuc = mysqli_query($con,"DELETE FROM tb_haber_kategori WHERE kategori_id IN ($secilenler)");
if($coklu_sonuc>0){
$responses['status'] = 'success';
$responses['titles'] = 'SİLİNDİ';
$responses['message'] = 'Kategori silme başarılı ...';
}
else {
$responses['status'] = 'error';
$responses['titles'] = 'HATA';
$responses['message'] = 'Bir sorun oluştu ...
<br>Lütfen bu durumu ProPANEL yetkililerine bildirin..!';
}
}
echo json_encode($responses);
Where is my mistake?
can you help me?