Jump to content

Basic if then... help plz


bowhuntertech

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/250024-basic-if-then-help-plz/
Share on other sites

$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";

 

}

<!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.

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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.