Jump to content

[SOLVED] Problem with OnClick Session Variable


Glenugie

Recommended Posts

I have a page with two images on it, these images are links, on clicking them they are meant to set a session variable equal to a given value, so that they know which part of a database to query. There is a problem with it however as it sets it equal to the second one, no matter which image I select.

The code is:

13- <td width=0 height=80><a href="fight.php" onclick="<?
14- session_register("area");
15- $_SESSION["area"] = '4';
16- ?>"><img src="3.jpg" width=487 height=164 border=0 alt="Behind the Clock Face" title="Behind the Clock Face"></a></td>
17- </tr>
18- 
19- <tr>
20- <td width=0 height=80><a href="fight.php" onclick="<?
21- session_register("area");
22- $_SESSION["area"] = '5';
23- ?>"><img src="5.jpg" width=487 height=114 border=0 alt="Entrance" title="Entrance"></a></td>
24-</tr>

It sets it equal to 5 when either image is clicked, is there a problem with the syntax that I am not seeing?

 

Thanks in advance for any help :)

 

~Glenugie~

Instead of using the onclick attribute in the link, add a GET variable to the link:

 

<td width=0 height=80>
    <a href="fight.php?area=4"><img src="3.jpg" width=487 height=164 border=0 alt="Behind the Clock Face" title="Behind the Clock Face"></a>
</td>

 

And then in fight.php add your session code.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.