0

Here is my HTML code

<div id="port" align="center">
    <form  action="NetRulez.php" method="GET">
        <input type="number" name="i" value="" placeholder="enter real IP">
        <br/>
        <input type="number" name="port" value="<?php echo $port ?>" placeholder="enter port ID">
        <br/>
        <input type="submit" name="submit" value="Suche">       
    </form>
</div>

and here is my php code:

<?php
if(isset($_POST['submit']))
$port = $_GET['port'];
{
switch($port){
    case ($port>= "1024" && $port<= "2031"): 
            echo "0";
        break;
        case ($port>= "2032" && $port<= "3039"): 
            echo "1";
        break;

        default: //default
            echo "within no range";
        break;
}
}

?>

I want to enter a port number, for example, 1024 in HTML form and it should echo the output from PHP code. the port value should fit the range I mentioned in switch case.

1 Answers1

4

This line is incorrect...

if(isset($_POST['submit']))

You are using $_POST, however you are sending via GET method.

<?php
if((isset($_GET['submit'])) && (isset($_GET['port')))
{
  $port = $_GET['port'];

  switch($port)
  {
    case ($port>= "1024" && $port<= "2031"): 
      echo "0";
        break;
    case ($port>= "2032" && $port<= "3039"): 
      echo "1";
        break;

    default: //default
      echo "within no range";
        break;
  }
}

?>
davidev
  • 7,694
  • 5
  • 21
  • 56