How can an Alert Box be properly integrated for a security confirmation before data deletion in PHP?

When deleting data in PHP, it's important to confirm the action with the user to prevent accidental deletions. This can be done by integrating an Alert Box to prompt the user for a confirmation before proceeding with the deletion.

<?php
if(isset($_POST['delete'])){
    echo '<script>alert("Are you sure you want to delete this data?")</script>';
    // Add code here to handle deletion if user confirms
}
?>