Page 1 of 1

Passing variables between pages with php

Posted: Mon Mar 15, 2004 6:30 am
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.

Posted: Mon Mar 15, 2004 6:38 am
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

Posted: Tue Mar 16, 2004 4:01 am
by pfairclough
great stuff, that does the trick

thanks for your help