This topic is locked
[SOLVED]

 Setting a Session Variable

4/22/2011 2:58:04 PM
PHPRunner General questions
bbarker author

Upon Login, I want to pull an existing value (CurrentYear) and make it a $Session variable.



$str = "select CurrentYear from tbldefaultlookup where DefaultID = 1";

$rs = db_query($str);

$data = db_fetch_array($rs);

$CurrentYearTmp = $data["CurrentYear"];

$_SESSION["CurrentYear"] = $values["CurrentYearTmp"];


What am I mixing up? :-(

D
Dale 4/22/2011

I hope I am right, hate to waste your time.

But I would just change the line

$_SESSION["CurrentYear"] = $values["CurrentYearTmp"];

to

$_SESSION["CurrentYear"] = $CurrentYearTmp;
Hopefully you get the results your looking for.

Sergey Kornilov admin 4/22/2011
$str = "select CurrentYear from tbldefaultlookup where DefaultID = 1";

$rs = db_query($str);

$data = db_fetch_array($rs);

$_SESSION["CurrentYear"] = $data["CurrentYear"];
bbarker author 4/22/2011

Thanks guys... but neither of these worked.... ?!?!?
After I update the TABLE which has CURRENT RECORD in it, I have an EVENT:

$_SESSION["CurrentYear"] = $values["CurrentYear"];

This works good.
But in my original post above, I am trying to SET the SESSION variable after logging in. And that's not working.
TABLE: tbldefaultlookup

DefaultID = 1

CurrentYear =2012
There is only one record in this table. I want to set this value (CurrentYear) to $_Session["CurrentYear"]
Thanks in advance for any ideas.

Sergey Kornilov admin 4/22/2011

Your code looks correct. Probably it needs to be placed to another event or there is something else that needs to be tweaked.
If you have a support contract post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program.

bbarker author 4/22/2011

Thanks Sergey... I just uploaded it and will send an email to support.

bbarker author 4/25/2011

I finally got it to work by myself.
REMOVED

it from the Events.php location

(after Successful Login)
and
ADDED

it to the List Page: Before Process EVENT
Working code is:
// List page: Before process

function BeforeProcessList(&$conn)

{

// Save CurrentYear as a Session variable

$str = "select CurrentYear from tbldefaultlookup where DefaultID = 1";

$rs = CustomQuery($str);

$data = db_fetch_array($rs);

$_SESSION["CurrentYear"] = $data["CurrentYear"];
---Bill B