Confirm button before running deleting routine from website

Yes, you can add a confirm button before running a delete routine on a website using PHP. Here is an example of how this can be done:

  1. Create a delete button or link that, when clicked, will trigger the delete routine. For example, you can create a link with the text "Delete" and an id of "delete_button".
<a href="#" id="delete_button">Delete</a>
  1. Use JavaScript to attach an event listener to the delete button. When the button is clicked, the event listener will display a confirm dialog box asking the user to confirm or cancel the delete action.
document.getElementById("delete_button").addEventListener("click", function(event){
    if(confirm("Are you sure you want to delete this item?")){
        // Run the delete routine

Watch a course Learn object oriented PHP

  1. To run the delete routine, you can use an ajax call to the PHP script that performs the delete action.
if(confirm("Are you sure you want to delete this item?")){
                id: item_id
            success: function(response) {
                    //Do something like removing the item from the page
  1. In the PHP script, you can use the received id to delete the item from the database
    $id = $_POST['id'];
    //Delete query here
    echo "success";

This is a basic example and can be modified to fit the specific requirements of your website.