I have a table whose view is something like this
ID NAME LOCATION DELETE
1 sam US delete
I have a statement from the table that deletes the given row
echo "<td><a href=\"delete_members.php?id=".$row['id']."\">Delete</a></td>";
It redirects to delete_members.php page and the row gets deleted, however i wish to display an alert box that makes sure that the user wants to delete the row or not. for it i have a code
<button onclick="myFunction()">Delete</button>
<script>
function myFunction() {
var x;
if (confirm("Press a button!") == true) {
window.location="yourphppage.php"; // not sure which link should be placed here
return true;
} else {
window.location="index.php";
return true;
}
document.getElementById("demo").innerHTML = x;
}
</script>
code for the delete_members.php page
<?php
include('admin_session.php');
$con=mysqli_connect("abc.com","abc","abc","abc");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id = $_GET['id'];
mysqli_query($con,"DELETE FROM members WHERE id='".$id."'");
mysqli_close($con);
header("Location: admin_member_list.php");
?>
However, i am unable to use the confirmation script with the statement in a proper way. i want that the alert box gets popped up(i.e the script runs) after i click on the edit button that is present on the first statement given above and then if the user confirms it should run the delete_members.php script. would appreciate if someone could guide me