What's new

Bakit ganito error ko sa delete

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,168
Solutions
2
Reaction
103
Points
497
Age
30
bakit kaya ito hindi nag papakita message na to

if (result.isConfirmed) {
Swal.fire(
'Deleted!',
'Your file has been deleted.',
'success'
)
}

ito code ko sa sweetalert:

$('.btn-delete').on('click', function(e) {
e.preventDefault();
const href = $(this).attr('href')
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.value) {
document.location.href = href;
}
})
})
if (result.isConfirmed) {
Swal.fire(
'Deleted!',
'Your file has been deleted.',
'success'
)
}

ito code ko sa confirmdelete:

<?php
include '../config/config.php';
$id_comment = $_REQUEST['comment_id'];
$sql_delete = mysqli_query($con, "DELETE * FROM post where comment_id = '$id_comment'");
header('location:dashboard.php');
?>
 
Mayroon kang ilang mga error sa iyong code na nagiging sanhi ng hindi pagpapakita ng mensahe sa pag-delete.

Una, dapat mong ilipat ang code na nagpapakita ng mensahe sa loob ng if(result.isConfirmed) block ng then function. Sa kasalukuyan, ito ay nasa labas ng then function, kaya hindi ito naitatawag.

Narito ang inaayos na code na may mga pagbabago:

JavaScript:
$('.btn-delete').on('click', function(e) {
    e.preventDefault();
    const href = $(this).attr('href')
    
    Swal.fire({
        title: 'Are you sure?',
        text: "You won't be able to revert this!",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, delete it!'
    }).then((result) => {
        if (result.isConfirmed) {
            Swal.fire(
                'Deleted!',
                'Your file has been deleted.',
                'success'
            );
            document.location.href = href;
        }
    });
});

Napansin ko rin na mayroon kang error sa iyong DELETE query sa iyong confirmdelete file. Ang tamang syntax para sa DELETE query ay DELETE FROM table_name at hindi DELETE * FROM table_name. Kaya dapat mong palitan ang query ng ganito:

PHP:
$sql_delete = mysqli_query($con, "DELETE FROM post WHERE comment_id = '$id_comment'");

Tandaan din na pagkatapos mong matanggal ang comment, kailangan mo ring i-redirect ang user sa dashboard.php gamit ang header function:

PHP:
header('location:dashboard.php');

Umaasa akong makatulong ito sa iyo sa pag-aayos ng iyong code at mapapakita mo nang matagumpay ang mensahe sa pag-delete. Kung mayroon kang mga karagdagang tanong, huwag mag-atubiling magtanong ulit.
 
Mayroon kang ilang mga error sa iyong code na nagiging sanhi ng hindi pagpapakita ng mensahe sa pag-delete.

Una, dapat mong ilipat ang code na nagpapakita ng mensahe sa loob ng if(result.isConfirmed) block ng then function. Sa kasalukuyan, ito ay nasa labas ng then function, kaya hindi ito naitatawag.

Narito ang inaayos na code na may mga pagbabago:

JavaScript:
$('.btn-delete').on('click', function(e) {
    e.preventDefault();
    const href = $(this).attr('href')
   
    Swal.fire({
        title: 'Are you sure?',
        text: "You won't be able to revert this!",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, delete it!'
    }).then((result) => {
        if (result.isConfirmed) {
            Swal.fire(
                'Deleted!',
                'Your file has been deleted.',
                'success'
            );
            document.location.href = href;
        }
    });
});

Napansin ko rin na mayroon kang error sa iyong DELETE query sa iyong confirmdelete file. Ang tamang syntax para sa DELETE query ay DELETE FROM table_name at hindi DELETE * FROM table_name. Kaya dapat mong palitan ang query ng ganito:

PHP:
$sql_delete = mysqli_query($con, "DELETE FROM post WHERE comment_id = '$id_comment'");

Tandaan din na pagkatapos mong matanggal ang comment, kailangan mo ring i-redirect ang user sa dashboard.php gamit ang header function:

PHP:
header('location:dashboard.php');

Umaasa akong makatulong ito sa iyo sa pag-aayos ng iyong code at mapapakita mo nang matagumpay ang mensahe sa pag-delete. Kung mayroon kang mga karagdagang tanong, huwag mag-atubiling magtanong ulit.
ang bilis naman mag laho ng message na to wala man lang OK na button na
'Your file has been deleted.',

Mali ata yung DELETE * from
Dapat DELETE from lang
ok n po maam yun message alert na lang po
 
ang bilis naman mag laho ng message na to wala man lang OK na button na
Pasensya na sa abalang dulot ng hindi tamang pagkakasulat ko sa previous response. Narito ang naayos na code na naglalaman ng tamang syntax para sa pagpapakita ng mensahe na may OK button matapos mag-delete:

JavaScript:
$('.btn-delete').on('click', function(e) {
    e.preventDefault();
    const href = $(this).attr('href');
   
    Swal.fire({
        title: 'Are you sure?',
        text: "You won't be able to revert this!",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, delete it!'
    }).then((result) => {
        if (result.isConfirmed) {
            $.ajax({
                url: 'confirmdelete.php',
                type: 'POST',
                data: {comment_id: <?php echo $id_comment; ?>},
                success: function(data) {
                    Swal.fire(
                        'Deleted!',
                        'Your file has been deleted.',
                        'success'
                    ).then(function() {
                        location.reload();
                    });
                },
                error: function() {
                    Swal.fire(
                        'Error!',
                        'An error occurred while deleting the file.',
                        'error'
                    );
                }
            });
        }
    });
});

Sa iyong confirmdelete.php file, siguraduhin na ang $id_comment variable ay nasa tamang format at may laman. Maaring mong gamitin ang $_REQUEST['comment_id'] o $_POST['comment_id'] depende sa kung paano ito ipinasa sa confirmdelete.php. Narito ang isang halimbawa ng paggamit ng $_POST['comment_id']:

PHP:
<?php
include '../config/config.php';
$id_comment = $_POST['comment_id'];
$sql_delete = mysqli_query($con, "DELETE FROM post WHERE comment_id = '$id_comment'");
if($sql_delete) {
    echo "success";
} else {
    echo "error";
}
?>

Sa iyong swal.fire function, nagdagdag ako ng success callback function na nagre-reload sa page matapos ang deletion. Kung nais mong i-redirect ang user sa ibang page pagkatapos ng deletion, maaari mong palitan ang location.reload() sa naaangkop na redirect code.

Inaasahan kong makatulong ito sa iyo sa pag-aayos ng iyong code at mapakita mo nang matagumpay ang mensahe sa pag-delete na may OK button. Kung mayroon kang karagdagang mga katanungan, huwag mag-atubiling magtanong ulit.
 
Pasensya na sa abalang dulot ng hindi tamang pagkakasulat ko sa previous response. Narito ang naayos na code na naglalaman ng tamang syntax para sa pagpapakita ng mensahe na may OK button matapos mag-delete:

JavaScript:
$('.btn-delete').on('click', function(e) {
    e.preventDefault();
    const href = $(this).attr('href');
  
    Swal.fire({
        title: 'Are you sure?',
        text: "You won't be able to revert this!",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, delete it!'
    }).then((result) => {
        if (result.isConfirmed) {
            $.ajax({
                url: 'confirmdelete.php',
                type: 'POST',
                data: {comment_id: <?php echo $id_comment; ?>},
                success: function(data) {
                    Swal.fire(
                        'Deleted!',
                        'Your file has been deleted.',
                        'success'
                    ).then(function() {
                        location.reload();
                    });
                },
                error: function() {
                    Swal.fire(
                        'Error!',
                        'An error occurred while deleting the file.',
                        'error'
                    );
                }
            });
        }
    });
});

Sa iyong confirmdelete.php file, siguraduhin na ang $id_comment variable ay nasa tamang format at may laman. Maaring mong gamitin ang $_REQUEST['comment_id'] o $_POST['comment_id'] depende sa kung paano ito ipinasa sa confirmdelete.php. Narito ang isang halimbawa ng paggamit ng $_POST['comment_id']:

PHP:
<?php
include '../config/config.php';
$id_comment = $_POST['comment_id'];
$sql_delete = mysqli_query($con, "DELETE FROM post WHERE comment_id = '$id_comment'");
if($sql_delete) {
    echo "success";
} else {
    echo "error";
}
?>

Sa iyong swal.fire function, nagdagdag ako ng success callback function na nagre-reload sa page matapos ang deletion. Kung nais mong i-redirect ang user sa ibang page pagkatapos ng deletion, maaari mong palitan ang location.reload() sa naaangkop na redirect code.

Inaasahan kong makatulong ito sa iyo sa pag-aayos ng iyong code at mapakita mo nang matagumpay ang mensahe sa pag-delete na may OK button. Kung mayroon kang karagdagang mga katanungan, huwag mag-atubiling magtanong ulit.
di na po sya nadedelet o di na nag fufunction
 
di na po sya nadedelet o di na nag fufunction
Paumanhin kung may mga pagkakamali sa aking mga naunang mga tugon. Narito ang naayos na code para sa tamang pag-delete ng data:

JavaScript:
$('.btn-delete').on('click', function(e) {
    e.preventDefault();
    const href = $(this).attr('href');
  
    Swal.fire({
        title: 'Are you sure?',
        text: "You won't be able to revert this!",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, delete it!'
    }).then((result) => {
        if (result.isConfirmed) {
            $.ajax({
                url: 'confirmdelete.php',
                type: 'POST',
                data: {comment_id: <?php echo $id_comment; ?>},
                success: function(data) {
                    if (data == 'success') {
                        Swal.fire(
                            'Deleted!',
                            'Your file has been deleted.',
                            'success'
                        ).then(function() {
                            location.reload();
                        });
                    } else {
                        Swal.fire(
                            'Error!',
                            'An error occurred while deleting the file.',
                            'error'
                        );
                    }
                },
                error: function() {
                    Swal.fire(
                        'Error!',
                        'An error occurred while deleting the file.',
                        'error'
                    );
                }
            });
        }
    });
});

Sa iyong confirmdelete.php file, siguraduhin na ang $id_comment variable ay nasa tamang format at may laman. Maaring mong gamitin ang $_REQUEST['comment_id'] o $_POST['comment_id'] depende sa kung paano ito ipinasa sa confirmdelete.php. Narito ang isang halimbawa ng paggamit ng $_POST['comment_id']:

PHP:
<?php
include '../config/config.php';
$id_comment = $_POST['comment_id'];
$sql_delete = mysqli_query($con, "DELETE FROM post WHERE comment_id = '$id_comment'");
if($sql_delete) {
    echo "success";
} else {
    echo "error";
}
?>

Siguraduhin din na ang path ng confirmdelete.php ay tama.

Pinapayuhan ko na gamitin mo ang error handling sa iyong PHP code para masuri mo kung may mga error na nagaganap sa iyong query. Maaari mong gamitin ang mysqli_error() function upang maipakita ang mga detalye ng error. Halimbawa:

PHP:
<?php
include '../config/config.php';
$id_comment = $_POST['comment_id'];
$sql_delete = mysqli_query($con, "DELETE FROM post WHERE comment_id = '$id_comment'");
if($sql_delete) {
    echo "success";
} else {
    echo "error: " . mysqli_error($con);
}
?>

Sa pamamagitan ng paggamit ng error handling, malalaman mo ang mga posibleng sanhi ng hindi pag-delete ng data.

Inaasahan kong makatulong ito sa iyo sa pag-aayos ng iyong code at mapakita mo nang matagumpay ang mensahe sa pag-delete. Kung mayroon kang karagdagang mga katanungan, huwag mag-atubiling magtanong ulit.
 
Back
Top