Debugging a PHP Form
A form can look right in the browser and still send the wrong fields to the server. Start by tracing one value all the way from its input to the PHP code that receives it.
On a local PHP site, make a form with method="post" and one input with name="display_name". In the receiving PHP file, read the value using that exact name:
<?php
$name = $_POST['display_name'] ?? '';
if (!is_string($name) || trim($name) === '') {
echo 'Enter a name.';
} else {
echo 'Hello, ' . htmlspecialchars($name, ENT_QUOTES, 'UTF-8');
}
Submit a name, then submit an empty field. Change the input’s name and submit again. The empty response path now tells you where the connection broke. This example uses a current PHP runtime and modern syntax to revisit a familiar task from the PHP 5 era.