How can multiple clicks on a button be prevented in PHP to avoid executing the same update multiple times?

To prevent multiple clicks on a button in PHP, you can disable the button after it is clicked using JavaScript. This will prevent users from clicking the button multiple times and executing the same update multiple times. By disabling the button, you can ensure that the update process is only triggered once.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Your update code here
    
    // Disable the button after it is clicked
    echo '<script>document.getElementById("updateButton").disabled = true;</script>';
}
?>

<form method="post">
    <!-- Your form fields here -->
    <button type="submit" id="updateButton">Update</button>
</form>