Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    85
    Thanks
    53
    Thanked 0 Times in 0 Posts

    Undefined index with passing variables in URL

    PHP Code:
    <?php if(($_GET['m'] == "search") || (!isset($_GET['m']))) { ?>
    a
    <?php }
    elseif (
    $_GET['m'] == "guide") { ?>
    b
    <?php ?>
    I thought !isset would make the default page search.php have "a"
    But I get Notice: Undefined index: m...

    Thank you
    Last edited by RonnyNishimoto; 08-03-2012 at 01:34 PM.

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    723
    Thanks
    20
    Thanked 84 Times in 84 Posts
    i think you would need to check 'm' first:

    PHP Code:
    <?php 
    if (isset($_GET['m']){
     if (
    $_GET['m'] == "search") {
      
    a
     
    }
     elseif (
    $_GET['m'] == "guide") {
      
    b
     
    }
    }else{
     
    // m is not set
    }
    ?>

  • Users who have thanked Arcticwarrio for this post:

    RonnyNishimoto (08-03-2012)

  • #3
    New Coder
    Join Date
    Jul 2012
    Posts
    85
    Thanks
    53
    Thanked 0 Times in 0 Posts
    LOL

    Yeah when I switch it, it works:
    PHP Code:
    <?php if((!isset($_GET['m'])) || ($_GET['m'] == "search")) { ?>
    What an interesting language.

    Thank you again arctic!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •