What is the function of confirm() in PHP and how can it be used to create a dialogue box with two buttons?
The function of confirm() in PHP is to create a dialogue box with two buttons, typically "OK" and "Cancel", to prompt the user for confirmation before proceeding with an action. This can be useful for confirming a deletion or any other irreversible action in a web application.
<?php
if(isset($_POST['delete_button'])){
echo '<script>if(confirm("Are you sure you want to delete this item?")){
// Proceed with deletion
} else {
// Cancel deletion
}</script>';
}
?>