I've facing problem where, when the confirmation message appear, I click the cancel button, the data will be also deleted. Can someone suggest where need to be fix? Below is the code.
echo "<a onClick='myFunction()' href='./delete.php?userID=".$row['userID'] ."'><button>Delete</button></a>";
<script>
function myFunction() {
$r = confirm("OK to delete?");
if ($r == false) {
return false;
}
}
</script>
The anchor tag event has to be prevented when the 'Cancel' is clicked with event.preventDefault().
Example
<a onClick="myFunction()" href="https://google.com">Delete
<script>
function myFunction() {
let r = confirm("OK to delete?");
if (r == false) {
// It will prevent visit to 'https://google.com'
return event.preventDefault();
}
}
</script>