...

View Full Version : Using $_GET in links



psykx
11-16-2007, 06:45 PM
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?

_Aerospace_Eng_
11-16-2007, 06:49 PM
Not sure what you mean. Do you have an example link?

psykx
11-16-2007, 07:28 PM
<a href="test.php?link=new">new</a>



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?

_Aerospace_Eng_
11-16-2007, 07:33 PM
The script you posted has errors in it. You are missing a ) after the isset function call. Try this

echo (isset($_GET['link'])) ? "var found" : "var not found";

psykx
11-16-2007, 07:38 PM
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

<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?

Fumigator
11-16-2007, 07:55 PM
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)).

rpgfan3233
11-16-2007, 07:59 PM
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

<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:

<?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?

CFMaBiSmAd
11-16-2007, 08:02 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum