What is the correct syntax for outputting the value of the pressed button in PHP after submitting the form?

To output the value of the pressed button in PHP after submitting the form, you can use the $_POST superglobal array to access the value of the button that was clicked. You can check which button was pressed by checking its name attribute in the $_POST array. This allows you to determine the specific button that triggered the form submission.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (isset($_POST['submit_button_1'])) {
        echo "Button 1 was pressed";
    } elseif (isset($_POST['submit_button_2'])) {
        echo "Button 2 was pressed";
    }
}
?>

<form method="post">
    <button type="submit" name="submit_button_1" value="button1">Button 1</button>
    <button type="submit" name="submit_button_2" value="button2">Button 2</button>
</form>