Page 1 of 1

Passing variables from one page to another

Posted: Tue Jun 17, 2008 6:18 pm
by WhiteWolf
I have a page, galleries.php. It consists of thumbnail pictures, each representing a gallery of photos. The user clicks on a thumbnail which is linked to another page, results.php which searches a database, and displays all matching results. Here is the dilemma:
In the galleries page, I have the following -

Code: Select all

 
 <td><div align="center"><a href="showGallery.php?<?PHP echo(session_id()) ?>"><img name="igallery1" src="images/Gallery/image.jpg" width="164" height="116" alt="Birds of Prey" border=0></div></a><br><CENTER> gallery 1</CENTER></td>
                 
 


which passes the session ID from Galleries to showGallery.php. My question is, since the thumbnail is the link to the next page (i.e. showGallery), how can I specify which gallery was clicked? I can't specify it as a session variable, because as is, the script leaves the galleries.php page before I run any sort of check. I know it must be obvious, but I'm drawing a blank. Can anyone tell me a solution to this problem?

Re: Passing variables from one page to another

Posted: Tue Jun 17, 2008 11:48 pm
by Jasheppard
Well first of all, you are using incorrect html

you have:
<td><div align="center"><a href="showGallery.php?<?PHP echo(session_id()) ?>"><img name="igallery1" src="images/Gallery/image.jpg" width="164" height="116" alt="Birds of Prey" border=0></div></a><br><CENTER> gallery 1</CENTER></td>
which needs to be:

Code: Select all

<td><div align="center"><a href="showGallery.php?<?PHP echo session_id(); ?>"><img name="igallery1" src="images/Gallery/image.jpg" width="164" height="116" alt="Birds of Prey" border=0></a></div><br><CENTER> gallery 1</CENTER></td>
(code=html stuffs up on this lot?)

what i have changed:
1. you have a 'a' tag before the after the div but your ending it after the div? </div></a>
New: </a></div>
2. you need a semicolon ';' after the php code to end that command.
Old: <?PHP echo(session_id()) ?>
New: <?PHP echo(session_id()); ?> or <?PHP echo session_id(); ?>
I have never seen echo() before but echo ""; works

i have only been doing php for about a month now but yea.. hope that works.
i like debugging code 8)

Re: Passing variables from one page to another

Posted: Tue Jun 17, 2008 11:54 pm
by Benjamin
Well the session id is being passed, but it's currently not assigned to a variable.

You're looking for something more along the lines of:

Code: Select all

 
<td><div align="center"><a href="showGallery.php?sid=<?php echo(session_id()); ?>"><img name="igallery1" src="images/Gallery/image.jpg" width="164" height="116" alt="Birds of Prey" border=0></a></div><br><CENTER> gallery 1</CENTER></td>
I added sid=

Re: Passing variables from one page to another

Posted: Tue Jun 17, 2008 11:58 pm
by Jasheppard
good point, that would help

Re: Passing variables from one page to another

Posted: Wed Jun 18, 2008 9:17 am
by WhiteWolf
Thanks for the input. here's the thing, even if I assign the session ID to a variable like sid, how can I tell the script which gallery to display? In my example, I only posted one gallery, but there's actually 7 of them. I know normally you can pass variables in teh SESSION array, but here, once the user clicks on a thumbnail, it exits the gallery.php file, and launches the showGallery.php file. I don't see a way to say the user clicked on gallery1, or gallery2. The session ID will be passed, but how can I also pass a variable containing the gallery name?

Re: Passing variables from one page to another

Posted: Tue Jun 24, 2008 9:33 pm
by Jasheppard
I don't fully understand what you mean, but does this help?

<a href="showGallery.php?sid=<?PHP echo session_id(); ?>&galleryname=igallery1">

:?: :?: :?:

Re: Passing variables from one page to another

Posted: Tue Jun 24, 2008 10:26 pm
by WebbieDave
Jasheppard wrote:<a href="showGallery.php?sid=<?PHP echo session_id(); ?>&galleryname=igallery1">
Right. Then you're showGallery.php can:

Code: Select all

if ($_GET['galleryname'] == 'igallery1') {
    // do stuff with igallery1
}
or something like that.