I am trying to have the following script run when a button is pressed within a php page. The script is supposed to delete a row from a MySQL database table.
I have read from other previous questions that you cannot utilize a php within a javascript within a php page as the php runs along with the page load. Now as it currently sits, the data is indeed deleted, but that is when the page loads.
What is the proper way of having the following query run when a button is pressed in a php page? (FYI, I am using sweetalert)
<script>
function alertdelete() {
{
swal({
title: "Are you sure?",
text: "This delete is permanent!",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete == true) {
<?php
mysqli_query($db, "DELETE FROM employee WHERE EMPNO='$id'");
?>
swal("The employee has been deleted!", {
icon: "success",
});
} else {
swal("Ok, the employee will not be deleted!");
return;
}
<?php
openPage("employees.php",3000);
?>
});
}
}
</script>