Below I want to confirm before deleting a record, problem here is whether I select ok or cancel from confirmation box record gets deleted on both, secondly I am not getting redirected to my required page after deletion.
<script type="text/javascript">
function ConfirmDelete(){
if (confirm("Delete Account?")){
window.location='mains.php';
}
else {
// do nothing
}
}
</script>
if(isset($_POST['submit'])){
$que=$db->prepare("DELETE FROM blogs WHERE id = :id");
$que->execute(array(':id'=>$postId));
}
<form method="POST">
<input type="submit" name="submit" value="Delete" onclick="ConfirmDelete()" />
</form>
so as basically the
delete
button would submit the form we can change the html code of the form toand
ConfirmDelete
function toTypically I'd put an "action" on my form then a return false; in my javascript:
Then js: