This topic is locked

Posting a session variable into a field

8/25/2007 8:33:07 PM
PHPRunner General questions
2
2bluesfan author

Hi guys, I'd appreciate any help on this.
I have a session variable I need to set as the default value in a text field on a form. The value of this text field serves as a control for a drop down select/look up for another field in the same form.
This may help:
My session variable is "Chain" (and is set to a value selected from the user table when the user successfully logs in).

The value of this variable should be inserted into the Chain field on a form

The chain field serves as a control for listing a series of locations into another field on the same form based on the value of chain (lookup from the locations table).
I have tried setting the default value of the chain field to $_SESSION["Chain"] but this does not appear to work.
Any ideas appreciated. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=6095&image=1&table=forumtopics' class='bbc_emoticon' alt=':rolleyes:' />
2bluesfan

A
alang 8/26/2007

Try following code in the Add page: Before Display event
$smarty->assign("value_<your form field name>",$_SESSION["Chain"] );

2
2bluesfan author 8/28/2007

Try following code in the Add page: Before Display event

$smarty->assign("value_<your form field name>",$_SESSION["Chain"] );


Thanks Alan. I tried your suggestion with no success. I've also tried to echo the value of the variable (which does not display and as a result I've pretty much settled in my own mind that I'm not setting the value of the variable correctly.) As you can tell, I am not a programmer by any stretch of the imagination.
I was trying to set the value of the variable by using this code:
global $conn;

$rs = db_query( "select chain from users where 'user name' = '".$_SESSION['UserID']."' ",$conn);

$data=db_fetch_array($rs);

$_SESSION['chain'] = $data['chain'];
2bluesfan

Alexey admin 8/28/2007

Hi,
there is an error in your code - you confuse backquotes (`) with apostrophes (')

The proper line would be:

$rs = db_query( "select chain from users where `user name` = '".$_SESSION['UserID']."' ",$conn);

2
2bluesfan author 8/28/2007

Thank you Alexey, that was it!
2bluesfan