-1

Trying to get my external php code to display the message before but I am having a few issues. Could someone give me a hand or a couple of tips to progress?

I am trying to understand where I am going wrong but any help would definitely be appreciated. When I upload this to the filezilla server I get the following error.

Parse error: syntax error, unexpected 'echo' (T_ECHO) in / on line 13

HTML

<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Enter your information in the form below</title>
</head>
<body>

<!--  Form1.html -->
<form action="Form1.php" method="post">

<fieldset><legend>Enter a number below </legend>

<b><p>Your number: </b> <input type="text" name="number" size="4" maxlength="4">
</p>
</fieldset>

<div align="center"><input type="submit" name="submit" value="Submit"></div>

</form>



</body>
</html>

PHP

<?php

if(isset($_POST['$number'])){

  $number = $_POST['$number'];

  if($number < 10){

    echo "The number is smaller than 10";

  } else ($number < 10 && $number  > 100){

    echo "The number is between 10 and 100";

  } else ($number > 100){

    echo "The number is larger than 100";

  }

}

?>

2 Answers2

3

You are using if - else instead of if - else if

Update your code to this

$number = 10;

if ($number < 10) {
    echo "The number is smaller than 10";

} else if ($number >= 10 && $number < 100){
    echo "The number is between 10 and 100";

} else if ($number >= 100){
    echo "The number is larger than 100";
}

Also, $_POST['$number'] should either be $_POST[$number], if you want to use the $number as index or $_POST['number'] if you want to access the number value provided in post data

  • so i updated the code and when i run my html and hit submit it will just take me to a blank page and not echo(print) my any of the text. no matter what number i type in? suggestions? I update the php code and the html code is still the same from before – D Caldwell Oct 06 '17 at 03:32
  • 100){ echo "The number is between 10 and 100"; } else if ($number > 100){ echo "The number is larger than 100"; } } ?> – D Caldwell Oct 06 '17 at 03:32
  • Since your `$number` value is 10, which condition do you expect it to match? –  Oct 06 '17 at 03:41
  • i guess that's where the confusion is. I believe i would get a value of it. which is why its not returning anything. but the code states that if the number is between 10 and 100 then return "number is between 10 and 100. I am randomly getting an error for my if ($number <10){ line error which is weird because i didn't change anything on the code other than the $number =10. but then changed it back to how it was on the original code i received with you help. thanks again in advance. Just trying to get a better understanding of this/ – D Caldwell Oct 06 '17 at 04:51
  • I did not understand you, is your problem solved? Or were you asking me to clarify? Just in case use `<=` instead of `<`. Also your 2nd condition is wrong and will always result in false. I'll update the code to show the right conditions –  Oct 06 '17 at 05:10
0

To answer your question, use an elseif and not just else. Also it should be $_POST['number'] and not $_POST['$number']

Jerry U
  • 618
  • 9
  • 22