Hi guys.
I have an admin section on my website and I would like to display a question asking the user if they would really like to delete a record once clicked. I am using PHP and MySQL to delete records from a database but if somebody accidentally clicks the delete link then it deletes straight away. Would I need to use a JavaScript prompt message?
This is the delete link
this is the delete.php where the delete happens
and I was thinking of using this JavaScript code but it doesn't work
Any feedback would be much appreciated.
I have an admin section on my website and I would like to display a question asking the user if they would really like to delete a record once clicked. I am using PHP and MySQL to delete records from a database but if somebody accidentally clicks the delete link then it deletes straight away. Would I need to use a JavaScript prompt message?
This is the delete link
Code:
echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
this is the delete.php where the delete happens
Code:
<?php
include('connect.php');
if (isset($_GET['id']) && is_numeric($_GET['id']))
{
$id = $_GET['id'];
$result = mysql_query("DELETE FROM house_info WHERE id=$id")
or die(mysql_error());
header("Location:admin.php");
}
else
{
header("Location:admin.php");
}
?>
Code:
<a href="javascript:confirmation(<? echo $row['id']; ?>)">delete</a>
<script type="text/javascript">
<!--
function confirmation(ID) {
var answer = confirm("Delete entry "+ID+" ?")
if (answer){
alert("Entry Deleted")
window.location = "delete.php?act=trackdelete&id="+ID;
}
else{
alert("No action taken")
}
}
//-->
</script>
Comment