Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing variables to a new page?

Status
Not open for further replies.

xWastedMindx

Technical User
Sep 3, 2002
67
US
I have my page I've been working on. I have a few variables with info and stuff, and it needs to be passed to a new page.

eg. dvdName, dvdPrice, dvdID etc needs to be passed to a new page where it can be displayed in a layout and presented with more information about the movie ... price, descriptions, photo and whatnot. (similar to the way Amazon is set up, but not as complex)

I have the first page set up, and I figured out how to get the PHP to make links out of the string.
Code:
echo &quot;<a href='[URL unfurl="true"]http://sitename.org/index.php?dvdID=$dvdID&dvdName=$dvdName'>$dvdName</a>&quot;;[/URL]

But when I click the link it just reloads the current page and nothing happens. I guess that's because I haven't told the code what to do next...

I guess my question is, where do I go from here?
I'm a bit confused as to what to do next.
I need help...


&quot;Hey...Where are all the chicks?&quot; -- unknown
 
Ideally, you would only be passing the dvdID because that dvdID can always reference the dvdName in your database.

Where do you go next? What database are you using? You need to tell PHP to access it.



- - picklefish - -

Why is everyone in this forum responding to me as picklefish?
 
Hi xWasteMindx,

Now, after clicking the link, you will have the following variables available in index.php page:
Code:
$_GET['dvdId']
Code:
$_GET['dvdName']

So at the top of the page, you should have some database query like this:
Code:
$id=$_GET['dvdId'];
$result=mysql_query(&quot;SELECT * FROM `dvdtable` WHERE `id`='$id'&quot;,$mysql);
and now you have all the columns from database stored in the $result variable. As jimoblak said, you don't have to pass also the $dvdName variable because you can read it from database so passing $dvdId will be enough. The other things which should be done after the query I wrote above depend on what you actually would like to do ;-)
 
oh, just one suggestion:
if the link you wrote above is also located in the index.php page, you should have the code snippet (I wrote in the previous reply) enclosed in the if statement like this:
Code:
if(isset($_GET['dvdId'])) {
$id=$_GET['dvdId'];
$result=mysql_query(&quot;SELECT * FROM `dvdtable` WHERE `id`='$id'&quot;,$mysql);
// perform some action with the DVD info obtained from database
}
 
I guess I should have mentioned that I have all the query and DB connections done already. I was just looking for help as to how to make the links work correctly.

But fear not, because I've already figured it out shortly after posting this while playing with the code some more.

For some reason I had the link pointing to the same PHP page... whereas I needed to create a new PHP page, and 'Echo' my variables so they'll display on the new page when the link is clicked. So I guess this whole thread was sort of pointless.
Sorry to waste your all's time trying to help me out. Maybe next time before I post I'll work at it a bit longer before giving up and seeking help.

Thanks anyway though.

&quot;Hey...Where are all the chicks?&quot; -- unknown
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top