echo '<td><a href="delete.php?id='.$id.'"><img src="img/delete.png" width=20px height=20px name="delete"></a></td></tr>';
this is my img icon. whenever you click it, it will navigate you to a new page where the deletion happens.
echo "<script>window.confirm('Delete?')</script>";
$id=$_GET['id'];
$query = "UPDATE `main` SET status=0 where id = $id";
$sql = $db->prepare($query);
if ($sql->execute()) {
echo "<script>
window.location='view.php';
</script>";
}
?>
</body>
<script type="text/javascript" src="./static/dist/js/main.js"></script>
</html>
this is delete.php. but i need to check first if the window.confirm is true before doing the deletion. but i don't know how
Instead put the confirm()
in the link of image before navigating to another page
echo '<td><a href="delete.php?id='.$id.'" onclick="return confirm(\'Delete?\')"><img src="img/delete.png" width=20px height=20px name="delete"></a></td></tr>';
Try this example:
<?php { ?>
<a href="deleteme" onclick="return confirm('Are you sure?')">Delete</a>
<?php } ?>