samedi 15 septembre 2018

Echos showing before input is received

I am new at PHP. Basically, I'm trying to make a simple if else statement that will let someone know if they are too young to see a rated R movie. The problem that I'm having is that what I want to output is shown way before I even get the input (age).

enter image description here

This is my current code:

<form action="movieProgram.php" method="post">
How old are you? <input type="text" name="age"/>
<input type="submit">
</form>



<?php 

/*if ($age < 17){ 
The $_POST['age'] retrieves data from the
form that is named age

*/
$age = $_POST["age"];
if ($age == ""){
    echo "";
}
elseif ($age < 17){
    echo "You are too young to watch the movie.";
}
else {
    echo "You are old enough to watch the movie.";
}
 ?>

How would I fix it? Any suggestions?

Aucun commentaire:

Enregistrer un commentaire