Checked value post with ajax and php?

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.


<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

            $(document).on('click', '#btn_del', function(e){
                var data = $("#checkbox1-1").serializeArray();

        function SwalDeletes(data){
                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) {
                            url: 'delete.php',
                            type: 'POST',
                            data: data,
                            dataType: 'json'
                            swal(responses.titles, responses.message, responses.status);

                            swal(responses.titles, responses.message, responses.status);
                allowOutsideClick: false              

        function readProducts(){



    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)");

            $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?

You treat an array as a jQuery object (":checked")), but the error console would have told you that earlier.

Despite that, on the JS-side of things, you make data collection too complicated. It suffices to use serialize() on the checkboxes (no additional checks needed).

In PHP you have a gaping SQL injection hole. The select before the delete is completely unnecessary and you’re missing the json header for the response.


Could you code me how to do it?

No .

Why don’t you try yourself first?

I’m trying, my ajax and script experience is bad :frowning:

Well, for me at least the best way to learn is to have a go. If someone presents you with a solution without you doing anything, you won’t gain any experience. That might sound daunting and unhelpful, but it’s got to be worth you having a go?

I think you are right, thank you for your interest :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.