FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


help with IF statement





jstoeffler
I'm a beginner at php and I need some help with this.
I am trying to make a form that will come up with different statements based on what age you type in.
Right now if the age is less than or equal to 12 it will come up with "Greetings, fellow teenager.Isn't it your bedtime yet?"
How do I make it so that "Greetings, fellow teenager" will only come up if you are between 13 and 19?

here is the code
Code:
<html>
<body>
Welcome <?php echo $_POST["name"];
echo(" "); ?>
<?php echo $_POST["lname"]; ?>.
<br />
You are <?php echo $_POST["age"]; ?> years old!
<br>
<?php
$young="12";
$teen="19";
$old="20";
IF ($_POST["age"]<=$teen)
echo("Greetings, fellow teenager.");
IF ($_POST["age"]>=$old)
echo("You are an old fart!");
IF ($_POST["age"]<=$young)
echo("Isn't it your bed time yet?");

?>
<p>
<a href="index.php">Click here </a>to return to home.
</body>
</html>

I hope you can understand what I am trying to say.
Big thanks to anyone who can help me out.
BlackSkad
This should do the trick. It first checks if the age is larger than $old, then if it is between old and teen, between teen and young and finally less than young.

Maybe young can take a look at this page about control structures on the php.net website. (specially the part about 'if', 'else' and 'elseif'.

Code:
<?php
$age = $_POST['age'];
$young="12";
$teen="19";
$old="20";

if ($age >= $old) {
    echo ("You are an old fart!");
} elseif ($age < $told && $age >= $teen) {
    echo("Nor old, nor teenager");
} elseif ($age < $teen && $age >= $young) {
    echo("Greetings, fellow teenager.");
} else {
    echo("Isn't it your bed time yet?");
}
?>


Greatz,
BlackSkad
jstoeffler
that worked
tyvm (thank you very much)
Related topics
can i help?
Google Ads help fund Spyware ?
MySQL statement error (got me going)
Need help integrating html code into php
Question about a mySQL statement
[RESOLVED] phpbb Help with making an upload script.
Help! This small script has logical problems. Please help
Help needed with chained selects
Help with php email
Help With C++ Searching
Bored? Wanna help me out? Do my survey
need help with statistics/Data Analysis (urgent)
what is the difference between a Girl as a friend and a GF?
if statement
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.