How can multiple submit buttons in a PHP form be used to trigger different actions based on user input?

To trigger different actions based on user input with multiple submit buttons in a PHP form, you can use the name attribute of the buttons to differentiate between them. When the form is submitted, you can check which button was clicked by checking the value of the name attribute in the $_POST array. Depending on the value, you can then execute different actions or functions in your PHP code.

<form method="post" action="process_form.php">
    <button type="submit" name="action" value="save">Save</button>
    <button type="submit" name="action" value="update">Update</button>
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if ($_POST["action"] == "save") {
        // Save action
    } elseif ($_POST["action"] == "update") {
        // Update action
    }
}
?>