The "value" in the submit button is simply the text that's going to appear in the button. So PHP is looking for a submit that equals "click" but your form isn't passing one. Instead, have PHP simply look for submit:
<?php
if ($submit)
{
echo "Hello, $UserName";
}
else
{
echo '
<html><body>
<form method="post" action="hello.php">
Enter Your Name
<input type="text" name="UserName"></input><br>
<input type="submit" name="submit" value="click"></input>
</form>
</body></html>
';
}
?>
Now a text field is different. There the value could matter or not, depending on what you want.
if ($UserName == Somebody)
{
echo "Do this\n";
}
else
{
echo "Do that\n";
}
Or if it doesn't matter what the UserName's variable is, you could simply have the form make sure it got filled out:
if ($UserName)
{
echo "Do this\n";
}
else
{
echo "Hey you didn't fill out UserName!\n";
}
Or you could combine it all:
<?php
if ($submit)
{
if ($UserName)
{
echo "Hi $UserName!\n";
}
else
{
echo "Hey, you need to fill out the username!\n";
}
}
else
{
echo '
<html><body>
<form method="post" action="hello.php">
Enter Your Name
<input type="text" name="UserName"></input><br>
<input type="submit" name="submit" value="click"></input>
</form>
</body></html>
';
}
?>