Can any one tell me how to access a query string and how to test if it exists?
Basically when a user hits a page I need to test to see if a query string has been defined. If it is the first time they come to the page, then it won't be there and so needs to display a list of links which link to the same page but with a query string. So the second time they get there the query string will exist and it will pull a record from the database based on that query string.
My work in the past has been in ColdFusion and I know I would do it there by using isdefined("url.id") etc.
Thanks
WillowFae
Query Strings - detecting and accessing
Moderator: General Moderators
An update on this - I have now "sort of" determined how to access the query string. Obviously using the method below brings everything after the .php? - how do I just get the bit after the =
I am also still not sure how to test to see if it has been defined
The code I have so far is
$memid = $_SERVER['QUERY_STRING'];
if (!isset($memid))
{
printf("no query string");
}
else
{
printf($memid);
}
If I manually add a query string to the end of the url in the address bar, then it processes fine and goes to the else statement. But if there isn't one, I get the following error
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'
I am also still not sure how to test to see if it has been defined
The code I have so far is
$memid = $_SERVER['QUERY_STRING'];
if (!isset($memid))
{
printf("no query string");
}
else
{
printf($memid);
}
If I manually add a query string to the end of the url in the address bar, then it processes fine and goes to the else statement. But if there isn't one, I get the following error
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'
-
superwormy
- Forum Commoner
- Posts: 67
- Joined: Fri Oct 04, 2002 9:25 am
- Location: CT
All of the varialbes passed by the query string are set in the $_GET array.
So if you access this page:
http://www.domainname.com/index.php?myv ... econdvalue
Then $_GET['myvariable'] will equal 'mynewvalue'
Also $_GET['anothervar'] will equal 'mysecondvalue'
If you want soemthing other than that, you need to use $_SERVER['QUERY_STRING']
So if you access this page:
http://www.domainname.com/index.php?myv ... econdvalue
Then $_GET['myvariable'] will equal 'mynewvalue'
Also $_GET['anothervar'] will equal 'mysecondvalue'
If you want soemthing other than that, you need to use $_SERVER['QUERY_STRING']