+ Reply to Thread
Results 1 to 8 of 8

Thread: undefine index?????

  1. #1
    zyreena is offline x10Hosting Member zyreena is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    57

    undefine index?????

    PHP Code:
    if($_GET['view'] == 'login' or !isset($_GET['view'])) 
    wat wil i do so dat this condition will work. it gives me an error: undefined index: view
    beginner always starts from the scratch
    www.alliancetutorial.x10hosting.com

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: undefine index?????

    You need to actually reverse your statement. When PHP encounters what you have programmed now and $_GET['view'] is not set, it gives you the error.

    Code:
    if(!isset($_GET['view']) || $_GET['view'] == 'login')
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    zyreena is offline x10Hosting Member zyreena is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    57

    Re: undefine index?????

    whew. thnx. it works. wats d explanation there?
    beginner always starts from the scratch
    www.alliancetutorial.x10hosting.com

  4. #4
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: undefine index?????

    When you do something like if (condition 1 or condition 2 or condition 3...) the conditions are evaluated in order from left to right. So, if there's an error in condition 1, it will never reach condition 2 or 3. Since $_GET['view'] is not set, your condition 1 has an error - you are trying to operate on something that doesn't exist.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  5. #5
    ichwar's Avatar
    ichwar is offline Community Advocate ichwar is an unknown quantity at this point
    Join Date
    Dec 2008
    Location
    NC, USA
    Posts
    1,454

    Re: undefine index?????

    Quote Originally Posted by garrettroyce View Post
    When you do something like if (condition 1 or condition 2 or condition 3...) the conditions are evaluated in order from left to right. So, if there's an error in condition 1, it will never reach condition 2 or 3. Since $_GET['view'] is not set, your condition 1 has an error - you are trying to operate on something that doesn't exist.
    good catch garrett. The other thing to note with that chance zyreena is that in php there is no "or" you need to use the command "||" ;)

  6. #6
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: undefine index?????

    Quote Originally Posted by ichwar View Post
    good catch garrett. The other thing to note with that chance zyreena is that in php there is no "or" you need to use the command "||" ;)
    I actually think they added "and" and "or" in one of the recent PHP versions, but I could be wrong. I prefer the symbol syntax because I've used a lot of other C type languages and I'm stuck in my ways :P
    Edit:
    http://www.php.net/manual/en/languag...rs.logical.php

    I would still stick to the || operator because "or" operates differently.
    Last edited by garrettroyce; 05-20-2009 at 03:07 PM. Reason: Automerged Doublepost
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  7. #7
    zyreena is offline x10Hosting Member zyreena is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    57

    Re: undefine index?????

    hmmm. but i've read you can use 'or' and 'and' in the latest version. tnx guys for mor info
    beginner always starts from the scratch
    www.alliancetutorial.x10hosting.com

  8. #8
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: undefine index?????

    Feel free to use 'and' and 'or' forms when necessary if you understand operator precedence and can add explicit parentheses to:
    Code:
    $foo='a' or false ? 'b' : 'c' and 'd';
    $bar='a' || false ? 'b' : 'c' && 'd';
    so the parenthesized versions are parsed equivalently.

    In general, you'll use '&&' and '||' much more than 'and' and 'or'. If you don't understand precedence, you should study it before going much further.

+ Reply to Thread

Similar Threads

  1. [Info] Tutorial Requests and Index
    By jeeter in forum Tutorials
    Replies: 4
    Last Post: 05-11-2009, 01:14 PM
  2. Adding Index Page
    By danjay in forum Free Hosting
    Replies: 1
    Last Post: 04-11-2009, 03:19 PM
  3. [IPB] Contiguous Board Index
    By phenetic in forum Tutorials
    Replies: 5
    Last Post: 09-18-2005, 10:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers