未定义的索引错误。 这有什么不对吗? [关闭]

Need some help with a simple php code. When I try to access http://example.com/login.php, it gives me a warning "Notice: Undefined index: type in www.example.com on line 2". But, when Try to access http://example.com/login.php?type=InvalidLogin, everything works fine. Whats wrong in my code.

My Code:

<?
$type = $_REQUEST["type"];
if ($type == 'InvalidLogin') {
?>
Your login is invalid.

<?
} else {
?>
Your login is valid
<?
}
?>

Try and do the following:

<?php
  if(isset($_GET["type"]))
  {
     $type = $_GET["type"];
     if ($type == 'InvalidLogin') {
        echo "Your login is invalid.";
     } 
  }
  else
  {
    echo "Your login is valid";
  }

?>

you should use isset ($_REQUEST["type"]) to test the index

$_REQUEST["type"] 

is requesting data from url http://example.com/login.php?type=InvalidLogin. If there isn't type, it gets error cannot find 'type'.

And dont use $_REQUEST to get the data. use $_POST or $_GET