I'm using sweet alert dialog for delete confirmation.
If user click "Yes" -> Run SQL to delete.
If user click "No" -> Do nothing, keep record.
<?php
if(isset($_POST['button_delete'])) {
echo '<script type="text/javascript">';
echo 'setTimeout(function (){swal({
title: "Are you sure?",
text:"You will not be able to recover this course!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel please!",
closeOnConfirm: false,
closeOnCancel: false},
function(isConfirm)
{
if(isConfirm)
{
swal("Deleted!", "Your file has been deleted.", "success");';
$deleteCourse = mysqli_real_escape_string($conn, $_POST['button_delete']);
$user = mysqli_real_escape_string($conn, $_SESSION['session_user']);
mysqli_query($conn, "DELETE FROM enroll
WHERE CourseCode LIKE '$deleteCourse'
AND UserID=$user");
echo '
}
else
{
swal("Cancelled", "Your file is safe.", "error");
}})}, 100);';
echo '</script>';
?>
No matter I click "Yes" or "No", the SQL will still run and delete the record. How to make it do different function when clicking Yes/No?
Thank you for helping.