How can PHP be used to create a confirmation message before deleting a record in an application?

When deleting a record in an application, it is important to confirm with the user before proceeding to avoid accidental deletions. This can be achieved by using a simple JavaScript confirmation dialog in conjunction with PHP. When the delete button is clicked, a confirmation message will pop up asking the user to confirm the deletion. If the user clicks "OK", the PHP code will execute the deletion process.

<?php
if(isset($_POST['delete'])){
    // Display a confirmation message using JavaScript
    echo '<script>
            if(confirm("Are you sure you want to delete this record?")){
                // If user confirms, proceed with deletion
                // Add your deletion logic here
            }
          </script>';
}
?>