-2

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
<?
}
?>
Gordon
  • 312,688
  • 75
  • 539
  • 559
  • 1
    There is 1830 results for [Notice: Undefined Index](http://stackoverflow.com/search?q=Notice%3A+Undefined+index+%5Bphp%5D) in addition to the thousand of results a search engine will give you. I don't see anything in your question that warrants asking this yet another time. Please do research before asking questions. – Gordon Aug 19 '13 at 08:27

3 Answers3

2

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

?>
Conrad Lotz
  • 8,200
  • 3
  • 23
  • 27
1
$_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

Namal
  • 2,061
  • 3
  • 18
  • 26
0

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