I am trying to create a form in php with an else/if statement that asks the user for their name and age. It greets them with a welcome message and their name, and then if their age is 16 or over, the statement echos "You are old enough to volunteer for our program." If the user is under the age of 16, the statement will echo "Sorry, try again when you are older. Here is my code:
<form action="" method="post">
Name: <input type="text" name="postName">
Age: <input type="text" name="age"><br /><br />
<input type="submit">
</form>
<br />
Hello,
<?php
echo $_POST['postName'];
?>
!
<br>
<?php
$age = 'age';
if ($age>=16)
{
echo $_POST["you are old enough to volunteer for our program!"];
}
else {
echo $_POST["Sorry, try again when you're 16 or older."];
}
?>
The input form is shown correctly, but "Sorry, try again when you're 16 or older" already appears when I open the web page and when I put my name and age in there, the welcome message with the users name works correctly, but absolutely nothing happens with the age statement. It still just says "try again when you're older" no matter what age I put in. HELP :(