if(result.isConfirmed)
block ng then
function. Sa kasalukuyan, ito ay nasa labas ng then
function, kaya hindi ito naitatawag.$('.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;
}
});
});
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:$sql_delete = mysqli_query($con, "DELETE FROM post WHERE comment_id = '$id_comment'");
dashboard.php
gamit ang header
function:header('location:dashboard.php');
ang bilis naman mag laho ng message na to wala man lang OK na button naMayroon 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 ngif(result.isConfirmed)
block ngthen
function. Sa kasalukuyan, ito ay nasa labas ngthen
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 iyongDELETE
query sa iyongconfirmdelete
file. Ang tamang syntax para saDELETE
query ayDELETE FROM table_name
at hindiDELETE * 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 sadashboard.php
gamit angheader
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.
'Your file has been deleted.',
ok n po maam yun message alert na lang poMali ata yung DELETE * from
Dapat DELETE from lang
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:ang bilis naman mag laho ng message na to wala man lang OK na button na
$('.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'
);
}
});
}
});
});
<?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";
}
?>
location.reload()
sa naaangkop na redirect code.Pero naconfirm mo if nadelete sa database or kung saan man yung dinidelete mo?ang bilis naman mag laho ng message na to wala man lang OK na button na
ok n po maam yun message alert na lang po
di na po sya nadedelet o di na nag fufunctionPasensya 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 anglocation.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.
Paumanhin kung may mga pagkakamali sa aking mga naunang mga tugon. Narito ang naayos na code para sa tamang pag-delete ng data:di na po sya nadedelet o di na nag fufunction
$('.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'
);
}
});
}
});
});
<?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()
function upang maipakita ang mga detalye ng error. Halimbawa:<?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);
}
?>
opo sa meesage na lang poPero naconfirm mo if nadelete sa database or kung saan man yung dinidelete mo?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?