Sherrie
01-08-2007, 10:41 AM
I'm sure this is a very simple solution. I have found a few threads with similar problems but I have tried the solutions (namely checking that the session_start() was on every page and putting the { in front of the session variable, but both don't seem to be working for me.
As such, how do I convert a session variable to a local variable?
I've currently got this code:
$los=$_SESSION['answer'][los];
$los remains empty though.
When I tried the following, I got a parse error saying that there was an unexpected '{' on the line where i tried to convert it.
$age={$_SESSION['answer'][age]};
Can someone please tell me how to do this?
I've stored my session variables and have checked, and they work perfectly.
The problem I'm having is in referring to my session variables in my SQL statement
$query="INSERT INTO HGsurvey
VALUES ('$_SESSION['answer'][age]','$_SESSION['answer'][los]','$_SESSION['answer'][eecat]')";
mysql_query($query)
or DIE ("Couldn't insert questionnaire");
I kept getting a parse error that it was expecting a T_Variable and something about whitespace.
As such, I'm trying to assign the session variable to a local variable so that I could do this instead:
$query="INSERT INTO HGsurvey
VALUES ('$age',$los','eecat')";
mysql_query($query)
or DIE ("Couldn't insert questionnaire");
I tested it using echo, but while the session variable returned the value submitted in the form, the local variable returned an empty value.
As a note, I have ensured that every page has session_start(); at the top.
Thanks again!
As such, how do I convert a session variable to a local variable?
I've currently got this code:
$los=$_SESSION['answer'][los];
$los remains empty though.
When I tried the following, I got a parse error saying that there was an unexpected '{' on the line where i tried to convert it.
$age={$_SESSION['answer'][age]};
Can someone please tell me how to do this?
I've stored my session variables and have checked, and they work perfectly.
The problem I'm having is in referring to my session variables in my SQL statement
$query="INSERT INTO HGsurvey
VALUES ('$_SESSION['answer'][age]','$_SESSION['answer'][los]','$_SESSION['answer'][eecat]')";
mysql_query($query)
or DIE ("Couldn't insert questionnaire");
I kept getting a parse error that it was expecting a T_Variable and something about whitespace.
As such, I'm trying to assign the session variable to a local variable so that I could do this instead:
$query="INSERT INTO HGsurvey
VALUES ('$age',$los','eecat')";
mysql_query($query)
or DIE ("Couldn't insert questionnaire");
I tested it using echo, but while the session variable returned the value submitted in the form, the local variable returned an empty value.
As a note, I have ensured that every page has session_start(); at the top.
Thanks again!