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~

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.