I have a contact form.
Now when I need to delete a record, I need a confirmation box to ask for user's confirmation. I've achieved this, so far so good. But the record gets deleted for both OK
and Cancel
buttons.
My code is as follows:
<td><a href="edit.php?id=<?php $_SESSION["name"] = ""; $_REQUEST["id"]=$row["first_name"]; echo $row["first_name"]; $_SESSION["name"]=$row["first_name"]; ?>">Edit</a> / <a href="delete.php?id=<?php echo $row["first_name"]; ?>" onclick="check()"> Delete </a></td>
<script>
function check(){
if(confirm("Are you sure you want to delete?")){
window.location.href = "delete.php?id=<?php echo $row["first_name"]; ?>";
return true;
}
else{
header("Location: http://localhost/test/display.php?show_details=Show+Details");
return false;
}
}
</script>
What could I do to delete the records only after clicking OK
button in the confirmation box and return to display.php
(same page) on clicking Cancel
?
It should navigate to delete.php
only on clicking OK
and stay in display.php
on clicking Cancel
.
I'm new to PHP.. Help please...