SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: Page error

  1. #1
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Page error

    Is there a code i can use to output on the page "not specified" if the link is test.php?person= and it dosnt output if the link is test.php?person=whatever
    Animated Chatrooms - www.121chatrooms.net

  2. #2
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Denmark
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like this?

    PHP Code:
    <?php
    if (empty($_GET['person'])) {
        echo 
    'not specified';
    }
    else {
        
    // something else...
    }
    ?>

  3. #3
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Parse error: parse error in C:\Documents and Settings\Mike\Desktop\xampplite\htdocs\chat\chatharbour\test.php on line 1
    Animated Chatrooms - www.121chatrooms.net

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have a syntax error on line 1 of your test.php file.

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2006
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, the code above will return "not specified" if your URL goes like test.php?person=0

    If you want to accept 0 (zero) as possible valid argument, use:

    if ($_GET['person'] == '')

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So will that. 0 == '' in PHP.
    PHP Code:
    if ($_GET['person'] === ''

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2006
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sk89q View Post
    So will that. 0 == '' in PHP.
    PHP Code:
    if ($_GET['person'] === ''
    Not necessarily . Variables from $_GET array are always strings, so you're not comparing 0 == '', but "0" == '' which returns FALSE. Although I agree with you that === beats == in most cases.

  8. #8
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah yeah, I forgot. Haven't worked with PHP in a while.

    Worse of all, I even linked a reference that contradicted myself!

  9. #9
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by STeeL_LT View Post
    Variables from $_GET array are always strings,
    They can also be arrays, as well as type null.

    eg
    foo.php?array[]=a&array[]=b

    var_dump($_GET['array']);


    But yeah, you won't get a real type integer(except for array keys).

  10. #10
    SitePoint Enthusiast
    Join Date
    May 2006
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Forgot about arrays, crmalibu for the win


Bookmarks

Posting Permissions

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