Thread: PHP Sessions
View Single Post
  #4 (permalink)  
Old 07-04-09, 09:44 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 2,838
Thanks: 13
Thanked 11 Times in 10 Posts
No, sessions are not the same as your database. To use variables in a session you'll need to explicitly add the variable to the session itself, like this:

PHP Code:
// place this line at top of page before any output
session_start();

//create a var with a value
$testvar "myfirstname";

// register the variable into a session
$_SESSION['testvar'] = $testvar

On another page, you can then do this (again, you need to start the session as above):

PHP Code:
// this will print nothing because the variable hasn't 
// been retrieved from the session yet
print "TESTVAR: $testvar";

// now we'll retrieve the var from the session
$testvar $_SESSION['testvar'];

// this will print the text 'myfirstname'
print "TESTVAR: $testvar"
If you have a customer name saved in the database, you must first pull the name out of the database, then store it in a session.




Quote:
Originally Posted by craigfarrall View Post
Ok so if I have a customer first name saved in the db as 'fname' then I can use:

Code:
$_SESSION['fname'];
Then I can echo that out later to show the fname?
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data (scroll down)
Reply With Quote