SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Variables in URL

    ok, I have a question that is going to sound really dumb, but I can't get this to work

    if I have a URL like this:
    http://127.0.0.1/ThinkQuest/Admin/Bl...ditblocks&id=6
    and I try to use $id within the function (it is in the global line), $id should = 6 right?

  2. #2
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not 100% sure what u are doing... but u usualy use ? when sending variables through a link
    www.hfds.com?var=value
    there are more search engine frinedly ways though, you may want to look into that as well

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, since the forum cuts the URL, you can't see the whole thing, but that is what I'm doing

    Blocks.php?op=editblocks&id=6

  4. #4
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes... $id should be 6

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for some reason, its not working
    I tried echo $id; and it printed 0

  6. #6
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats weird, perhaps if you post your code we could see an error you missed.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function editblocks() {
    global 
    $baseurl$id$bgcolor4$bgcolor1;
    echo 
    $id;
    ... 
    PHP Code:
    switch ($op) {
    ...
            case 
    "editblocks":
                include (
    "$path/Header.php");
                
    editblocks();
                break;


  8. #8
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dont quote me on this one.. but Im pretty sure u have to pass a variable into the function.


    this wont work
    PHP Code:
    $i =5
    function blah()
    {
       echo 
    $i;
    }

    blah(); 
    this will
    PHP Code:
    $i =5
    function blah($var)
    {
       echo 
    $var;
    }
    blah($i); 

  9. #9
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    he is taking the variable in via global.

    Perhaps the PHP interpreter does not extract variables from the query string until they are needed. Since the first time they are needed is within another function you use global to call them thinking they exist globally, but since they weren't needed yet they don't.

    Just as an experiment trying doing something like this before you call your function

    $new_id = $id;

    and then in your function do

    global $new_id...

    see if that works.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums


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
  •