Glenugie Posted December 30, 2008 Share Posted December 30, 2008 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 https://forums.phpfreaks.com/topic/138920-solved-problem-with-onclick-session-variable/ Share on other sites More sharing options...
flyhoney Posted December 30, 2008 Share Posted December 30, 2008 You are confusing client-side and server-size code. You cannot use PHP and javascript interchangeably. Link to comment https://forums.phpfreaks.com/topic/138920-solved-problem-with-onclick-session-variable/#findComment-726491 Share on other sites More sharing options...
Glenugie Posted December 30, 2008 Author Share Posted December 30, 2008 Okay, would there be an alternative way to do it using HTML (or a way to do it in PHP that could bypass server side and client side issues)? I'm not so good with the advanced parts of PHP, I just try to keep it simple Link to comment https://forums.phpfreaks.com/topic/138920-solved-problem-with-onclick-session-variable/#findComment-726499 Share on other sites More sharing options...
flyhoney Posted December 30, 2008 Share Posted December 30, 2008 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 https://forums.phpfreaks.com/topic/138920-solved-problem-with-onclick-session-variable/#findComment-726504 Share on other sites More sharing options...
Glenugie Posted December 30, 2008 Author Share Posted December 30, 2008 Thanks, that worked perfectly, you are a star Link to comment https://forums.phpfreaks.com/topic/138920-solved-problem-with-onclick-session-variable/#findComment-726519 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.