Easy enough to use AJAX for this case. Just put your PHP in the scriptDelete.php file and make sure you pass the correct arguments and their values ββin the data property. In this example, I just pass id 5 .
<script type="text/javascript"> function confirmDelete() { if (confirm('Are you sure you want to delete this?')) { //Make ajax call $.ajax({ url: "scriptDelete.php", type: "POST", data: {id : 5}, dataType: "html", success: function() { alert("It was succesfully deleted!"); } }); } } </script> <input type='submit' name='submit' value='Delete' onclick='return confirmDelete()' />
Another way is to submit the form back to your own page, for example:
<form method="post" action="yourpage.php"> <input type="submit" name="submit" value="delete" onclick="return confirm('Are you sure you want to delete this?')" /> </form>
So, you just submit the form back to yourpage.php , and on top of this page you do something like:
<?php //Means the form was submitted if ($_POST['submit']) { $id = $_POST['idToDelete']; $query = "DELETE FROM products WHERE id = " . mysql_real_escape_string($id); mysql_query($query) or die(mysql_error()); } ?>
Jules source share