1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with PHP, $_GET variable

Discussion in 'PHP & Perl' started by sonic1234, Jun 24, 2012.

  1. sonic1234

    sonic1234 Junior Member

    Joined:
    Oct 19, 2009
    Messages:
    131
    Likes Received:
    25
    Occupation:
    Webmaster
    Location:
    Equinox
  2. Porthos

    Porthos Newbie

    Joined:
    Jun 23, 2012
    Messages:
    38
    Likes Received:
    2
    Use a condition to only establish the $result variable if the $_GET['value'] variable exists.

    if($_GET['value']){$result=$_GET['value'];}
     
  3. sonic1234

    sonic1234 Junior Member

    Joined:
    Oct 19, 2009
    Messages:
    131
    Likes Received:
    25
    Occupation:
    Webmaster
    Location:
    Equinox
    With this i get this error: Undefined variable: _Get
     
  4. Porthos

    Porthos Newbie

    Joined:
    Jun 23, 2012
    Messages:
    38
    Likes Received:
    2
    Try this:
    if(isset($_GET['value'])){$result=$_GET['value'];}

    Mind if I ask what version of PHP you're using?
     
  5. hameem

    hameem Elite Member

    Joined:
    Jul 21, 2011
    Messages:
    1,880
    Likes Received:
    985
    Location:
    221B Baker Street
    Check your syntax. Check everything is there like this "$_GET['value']" without the double quotes of course. If that doesn't help, paste that part of the code here.
     
  6. Stalli0n

    Stalli0n Junior Member

    Joined:
    Nov 17, 2010
    Messages:
    115
    Likes Received:
    83
    Location:
    Europe
    you can check with isset if a variable is set

    So in your example:

    Code:
    if (isset($_GET['value']))
    {
        $result = $_GET['value'];
    }
    
     
  7. sonic1234

    sonic1234 Junior Member

    Joined:
    Oct 19, 2009
    Messages:
    131
    Likes Received:
    25
    Occupation:
    Webmaster
    Location:
    Equinox
    The part of code is
    With issest whatever the condition is, the script always executes with else. Even if index.php?page=5 the script will go in else. $page is always 1, with isset.
     
    Last edited: Jun 24, 2012
  8. sonic1234

    sonic1234 Junior Member

    Joined:
    Oct 19, 2009
    Messages:
    131
    Likes Received:
    25
    Occupation:
    Webmaster
    Location:
    Equinox
    I am using:
    Apache Version :2.2.21 PHP Version :5.3.10
     
  9. MickMcG

    MickMcG Power Member

    Joined:
    Feb 24, 2011
    Messages:
    600
    Likes Received:
    164
    u can use an alternative to above which will also set a default value (if u havent already previously in ur code):
    Code:
    $result = ( isset( $_GET['value'] ) ) ? $_GET['value'] : "";
    the error u got "Undefined variable: _Get" is cos u forgot the $ sign in the $_GET part ;)
     
    • Thanks Thanks x 1
  10. plumbum416

    plumbum416 Registered Member

    Joined:
    Mar 17, 2011
    Messages:
    93
    Likes Received:
    16
    Thats because $_GET is case sensitive and you wrote
    Code:
    isset($_Get['page'])
    instead of
    Code:
    isset($_GET['page'])
     
  11. MickMcG

    MickMcG Power Member

    Joined:
    Feb 24, 2011
    Messages:
    600
    Likes Received:
    164
    edit: answered above :)
     
  12. sonic1234

    sonic1234 Junior Member

    Joined:
    Oct 19, 2009
    Messages:
    131
    Likes Received:
    25
    Occupation:
    Webmaster
    Location:
    Equinox
    Thanks a lot Mick, this code worked :D

    But can somebody tell me why, if else dint work it was same as the above code:
     
  13. BleuMunkiGraphics

    BleuMunkiGraphics Junior Member

    Joined:
    Jun 13, 2012
    Messages:
    155
    Likes Received:
    26
    Occupation:
    Graphic Designer
    Location:
    Houston,Texas
    true. php is fussy. Remember your Case
     
  14. sonic1234

    sonic1234 Junior Member

    Joined:
    Oct 19, 2009
    Messages:
    131
    Likes Received:
    25
    Occupation:
    Webmaster
    Location:
    Equinox
    Oh ok, i get it now, thanks a lot guys for your help and time :) :)