bowhuntertech Posted October 28, 2011 Share Posted October 28, 2011 Ok, right now I have a form on a webpage just a blank box titled "number" I need to enter a value in the box and have the script do the following: If the number is <10, display the message “The number is smaller than 10” If the number is between 10 and 100, display the message “The number is between 10 and 100” If the number is >100, display the message “The number is larger than 100” I just don't know how to link the value inputted in the box with this simple script.. I am sorry if this is vague if you need me to post pics of what I have so far please let me know Quote Link to comment https://forums.phpfreaks.com/topic/250024-basic-if-then-help-plz/ Share on other sites More sharing options...
Jocka Posted October 29, 2011 Share Posted October 29, 2011 $number = '1'; // THIS BEING YOUR NUMBER, I'M JUST MAKING ONE UP if($number < 10){ echo "The number is smaller than 10"; } else if($number < 10 && $number is > 100){ echo "The number is between 10 and 100"; } else if($number > 100){ echo "The number is larger than 100"; } Quote Link to comment https://forums.phpfreaks.com/topic/250024-basic-if-then-help-plz/#findComment-1283171 Share on other sites More sharing options...
bowhuntertech Posted October 29, 2011 Author Share Posted October 29, 2011 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Clasen - Simple HTML Form1</title> </head> <body> <form action="/Chapter2/form1.php" method="post"> <fieldset><legend>Enter a number below:</legend> <p><b>Number:</b> <input type="text" name="inputNum" size="10" maxlength="10" /></p> </fieldset> <div><input type="submit" name="submit" value="Submit" /> </form> </body> </html> How do I insert that into this so it runs correctly.. I'm sorry i'm so new I have been reading but i'm just not grasping it. Quote Link to comment https://forums.phpfreaks.com/topic/250024-basic-if-then-help-plz/#findComment-1283172 Share on other sites More sharing options...
Jocka Posted October 29, 2011 Share Posted October 29, 2011 I'm assuming this page is called "form1.php" if you're planning to show this information on the same page. If that is the case, try below: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Clasen - Simple HTML Form1</title> </head> <body> <form action="/Chapter2/form1.php" method="post"> <fieldset><legend>Enter a number below:</legend> <p><b>Number:</b> <input type="text" name="inputNum" size="10" maxlength="10" /></p> </fieldset> <div><input type="submit" name="submit" value="Submit" /> </form> <?php if(isset($_POST['inputNum'])){ $number = $_POST['inputNum']; if($number < 10){ echo "The number is smaller than 10"; } else if($number < 10 && $number is > 100){ echo "The number is between 10 and 100"; } else if($number > 100){ echo "The number is larger than 100"; } } ?> </body> </html> Otherwise i suppose if form1.php is on another page, just use the same info I added, on the page. Quote Link to comment https://forums.phpfreaks.com/topic/250024-basic-if-then-help-plz/#findComment-1283174 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.