SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: $_GET method?

  1. #1
    SitePoint Addict kiltman's Avatar
    Join Date
    Mar 2004
    Location
    scotland
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question $_GET method?

    hello,

    im currently coding a view_entries page for a guestbook script. i have the script working fine, the only problem i have is below:

    when im using a link such as

    localhost/index.php?page=1

    it works fine, however when i simply use

    localhost/index.php

    im getting

    Notice: Undefined index: page in C:\Apache2\htdocs\guestbook\show_entries.php on line 135

    i understand that this is saying the index page cannot be found on the url. how do i get around it so that when there isnt a page on the url it automattically goes to the first page?

    thanks in advance

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,423
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Assuming you have globals turned on:

    Code:
    if (!isset($page)) $page="1";
    This checks to see if there is a variable called $page with a value assigned to it. If not, it creates the variable and assigns it the value one (which I am assuming is for page 1).

  3. #3
    SitePoint Addict kiltman's Avatar
    Join Date
    Mar 2004
    Location
    scotland
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, i just got it before you replied, i totally forgot about the isset function, cheers for your help

  4. #4
    SitePoint Member
    Join Date
    Jun 2004
    Location
    WV: Close to Chaleston
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use a completely diferent method:

    PHP Code:
    if(!($p $_GET['page']))
    {
        
    $p 'home';


  5. #5
    SitePoint Evangelist Daijoubu's Avatar
    Join Date
    Oct 2002
    Location
    Canada QC
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't relay on register_globals, they're evil
    Use the super globals like 1veedo do (sound weird ), $_GET for example
    Speed & scalability in mind...
    If you find my reply helpful, fell free to give me a point

  6. #6
    SitePoint Addict kiltman's Avatar
    Join Date
    Mar 2004
    Location
    scotland
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah i did it the way that 1veedo did, i was just saying i forgot about the isset function for checking to see if a variable exists. thanks for all ur help

  7. #7
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $page  = (isset($_GET['page'])) ? $_GET['page'] : 'defaultpage' 


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
  •