Passing variables between pages with php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pfairclough
Forum Newbie
Posts: 2
Joined: Mon Mar 15, 2004 6:30 am
Location: UK

Passing variables between pages with php

Post by pfairclough »

I am fairly new to php and I am having some difficulty passing variables between pages using hyperlinks.

Im using a table to generate a list of items pulled from a database and hyperlinks to link the items to a second php page. This is the code I am using…

<td><a href="item.php?item=' . $row['ItemID'] . '">' . $row['ItemName'] . '</a></td>

This all seems to work fine until I get to the second page where I am unable to use the variable.

Is there any code that I need to include on the second page to retrieve the variable? So far I have been using $item which doesn’t seem to work.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If on the second page you are trying to do this:

Code: Select all

echo 'the value of item in the URL query string is: '.$item;
then you need to change the way you are trying to access the query string variable to:

Code: Select all

echo 'the value of item in the URL query string is: '.$_GET['item'];
Mac
pfairclough
Forum Newbie
Posts: 2
Joined: Mon Mar 15, 2004 6:30 am
Location: UK

Post by pfairclough »

great stuff, that does the trick

thanks for your help
Post Reply