This is a discussion on Change value of session variable by clicking href within the PHP Language forums, part of the PHP Programming Forums category; Hi Like to change the value of a session variable by clicking a link ------------------------------ <?php session_start(); session_register("cat&...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi
Like to change the value of a session variable by clicking a link ------------------------------ <?php session_start(); session_register("cat"); ?> <a href="index.php" onMousedown=<? $_SESSION['cat']=1; ?>Set cat to 1</a> <a href="index.php" onMousedown=<? $_SESSION['cat']=2; ?>Set cat to 1</a> ----------------------------- Any ideas why this is not working and how I could do it? Cheers Sunnyboy |
|
|||
|
sunnyboy@europe.com wrote:
> Any ideas why this is not working and how I could do it? > You are making the mistake to mix client side (javascript) and server side (PHP). Consider the following revision: <?php session_start(); if (isset($_GET['cat'])) { $_SESSION['cat'] = $_GET['cat']; } print isset($_SESSION['cat']) ? "cat is {$_SESSION['cat']}" : 'cat is not set<br />'; ?> <a href="index.php?cat=1">Set cat to1</a> <a href="index.php?cat=2">Set cat to 2</a> JW |
|
|||
|
Hmm, what you are trying to do is to control php directly through
javascript. it doesn't work that way... Here is an example that would work: <?php session_start(); if ( isset($_GET['cat']) ) { $_SESSION['cat'] = $_GET['cat']; } else { $_SESSION['cat']=0; } ?> <a href="index.php?cat=1">et cat to 1</a> <a href="index.php?cat=2">et cat to 2</a> Cat is : <?php echo $_SESSION['cat']; ?> |