<?php
$greeting = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = trim($_POST['name'] ?? '');
if ($name !== '') {
$greeting = "Hello, " . htmlspecialchars($name) . "!";
}
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<input type="text" name="name">
<button type="submit">Greet me</button>
</form>
<p><?php echo $greeting; ?></p>