Page 1 of 1

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

Posted: Fri Jul 16, 2004 1:30 pm
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!!!!

Posted: Fri Jul 16, 2004 1:48 pm
by PrObLeM
do you have session_start(); in there http://us4.php.net/session_start

Posted: Fri Jul 16, 2004 2:18 pm
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.