Setting a $_SESSION value as part of a link...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dardsemail
Forum Contributor
Posts: 136
Joined: Thu Jun 03, 2004 9:02 pm

Setting a $_SESSION value as part of a link...

Post by dardsemail »

I had another thread going but I realized I could solve my whole problem (or at least I believe I can) if I can just figure this part out...

I have some code which includes a link to another page. What I'd like to do is set the $_SESSION value for two values upon clicking of the link.

I've created a hidden field within the link to establish the value, now its just a question of being able to set the values when the user clicks on the link.

Here's a snippet of the code to see...

Code: Select all

<?php
<form action="<?=$_SERVER['PHP_SELF'];?>" name="frm_section" method="post"><table width="800px" align="center" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td align="center">
		<a href="aboutav.php<?php if( !empty($_POST['section']) ) { $_SESSION['section'] = $_POST['section']; $_SESSION['page'] = $_POST['section']; } echo (!empty($_SESSION['section']) ? '?section='.$_SESSION['section'] : '' ) ?>"><input name="section" type="hidden" value="aboutav"><img src="images/aboutus.gif" border="0" /></a>
		</td>
	</tr>
</table>
</form>

?>
What I'd like to have happen is to have the following $_SESSION values set:

$_SESSION['section'] = $_POST['section']
$_SESSION['page'] = $_POST['section']

These variables will be changing based on the links that the user selects. it will never be empty as I'm setting the values when the user comes to the site.

Yes - I know both are using the same $_POST value - that's okay. That's what I need them to do.

The PHP code embedded within the link was provided to me by someone on another thread - but it doesn't seem to be working.

Can someone far more intelligent than myself (which is probably anyone on this list!) please help me out here? I'm stuck! THANKS SO MUCH!!!!
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

do you have session_start(); in there http://us4.php.net/session_start
dardsemail
Forum Contributor
Posts: 136
Joined: Thu Jun 03, 2004 9:02 pm

Post by dardsemail »

yes, I do. its at the top of the page. I left out the code that was unnecessary for the purposes of this post.
Post Reply