Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    89
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Using $_GET in links

    I'm trying to create HTML links using the get variable. but it doesn't work unless there is an input item with the correct name. is there a way with an invisible input item? or a work around?

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Not sure what you mean. Do you have an example link?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Apr 2007
    Posts
    89
    Thanks
    1
    Thanked 2 Times in 2 Posts
    <a href="test.php?link=new">new</a>

    PHP Code:
    if( isset($_GET['link'])
    {
    echo 
    "var found";
    }else{
    echo 
    "var not found";

    always echo's var not found, is there another way to do this?

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    The script you posted has errors in it. You are missing a ) after the isset function call. Try this
    PHP Code:
    echo (isset($_GET['link'])) ? "var found" "var not found"
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New Coder
    Join Date
    Apr 2007
    Posts
    89
    Thanks
    1
    Thanked 2 Times in 2 Posts
    dam, thats not quite what I meant that code was just to illustrate the point. that script (with the missing ')' ) works fine if there is
    Code:
    <form action="test.php" method="get">
    <input name="link">
    but if that isn't on the page and the code is called by a link e.g <a href="test.php?link=new">new</a> it doesn't set the $_GET variable is there a way around this?

  • #6
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    the code is called by a link e.g <a href="test.php?link=new">new</a> it doesn't set the $_GET variable is there a way around this?
    That will certainly populate the $_GET['link'] variable. I'm not sure what's different about what you're doing, or what may be different with your installation of PHP but that's the point of a query string, to feed values into a script.

    You may be able to find the problem if you display the entire $_GET array at the top of your script (i.e. print_r($_GET)).

  • #7
    Regular Coder
    Join Date
    Mar 2005
    Location
    D0u$h!t3 k4?
    Posts
    512
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by psykx View Post
    dam, thats not quite what I meant that code was just to illustrate the point. that script (with the missing ')' ) works fine if there is
    Code:
    <form action="test.php" method="get">
    <input name="link">
    but if that isn't on the page and the code is called by a link e.g <a href="test.php?link=new">new</a> it doesn't set the $_GET variable is there a way around this?
    What exactly are you trying to do? Why isn't <a href="path/whatever.php?link=new">New</a> working for you? Are you sure you aren't viewing a cached page? (Ctrl-F5 usually does a hard refresh) A simple get.php page that works for me:
    Code:
    <?php
    if (!isset($_GET['link']) || (strlen($_GET['link']) == 0)) {
    ?>
    
    <a href="get.php?link=new">New</a>
    
    <?php
    }
    else
        echo "Set!";
    ?>
    That works fine for me. Every time I go to get.php?link=whatever, I see "Set!" on my screen. Every time I go to get.php, get.php?, get.php?link, or get.php?link= I always see the link.

    Edit:
    I'm just trying to figure out what you're doing. Do you need the get variable in the URL in order to create the link to the page that the get variable points to, as in a sort of permalink?
    Last edited by rpgfan3233; 11-16-2007 at 07:05 PM.
    PHP Code:
    $hello file_get_contents('hello.txt'); echo $hello
    hello

  • #8
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,039
    Thanks
    2
    Thanked 316 Times in 308 Posts
    I'll echo() what has already been said. The posted link will cause the posted code to work correctly.

    If it is not working for you, something that your actual code is doing is preventing it or is overwriting the value (don't forget that if register globals are on and you have other POST/GET/COOKIE/SESSION/program variables with the same name "link" that the last one in the default assignment order will overwrite any earlier ones - damn those register globals.) You would need to post your actual code to get the quickest solution to the problem.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

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