How can the PHP script be programmed to prompt the user for confirmation before deleting a record when clicking on a button?

To prompt the user for confirmation before deleting a record in PHP, you can use JavaScript's `confirm()` function. This function will display a dialog box with an OK and Cancel button, allowing the user to confirm or cancel the deletion action. By integrating this JavaScript function with PHP, you can ensure that the user confirms their intention before the record is deleted.

<?php
if(isset($_POST['delete'])){
    // Display a confirmation dialog using JavaScript
    echo '<script>
            if(confirm("Are you sure you want to delete this record?")){
                // If confirmed, proceed with the deletion
                // Place your delete record code here
            } else {
                // If canceled, do nothing or redirect back to the page
                // header("Location: your_page.php");
            }
          </script>';
}
?>