Why does the PHP code display the same word on each click of the button?

The issue is that the PHP code is not updating the displayed word on each click of the button because the variable holding the word is not being changed. To solve this, you can use a session variable to store the word and update it on each click of the button.

<?php
session_start();

if (!isset($_SESSION['word'])) {
    $_SESSION['word'] = 'Hello';
}

if (isset($_POST['generate'])) {
    // Generate a random word here
    $_SESSION['word'] = 'RandomWord';
}

echo $_SESSION['word'];
?>

<form method="post">
    <button type="submit" name="generate">Generate Random Word</button>
</form>