Page 1 of 1

Session Variables in Function

Posted: Wed Mar 23, 2005 11:53 am
by hbnmgr
Did a Search but couldn't find an answer on the following ...

Problem:
In a Function, I want to get information, from the database, on a certain member and make these available as session variables. This way they can replace certain keywords on the page.

Q:
How do code the function to make the variables pulled as Session Variables?

In addition, can these be available on the first page, wherein the calls to the database, and the string replacements are on the same page? (because according to the manual, session variables are not available till the second page - utilizing session start)

Code so far ...

Code: Select all

function get_member_info()
{
// query database for member info
   $conn = db_connect();
   $query = "select memid, cbid, coname, firstname, lastname, address, city, state, zip, phone, mememail, otherlink, opfield1, opfield2
             from members where memdir = $memdir";
   $result = @$conn->query($query);
   if (!$result)
   	return false;
   
}
Thanks!
SRR


feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Wed Mar 23, 2005 12:23 pm
by shiznatix
im not real sure what you are asking but i think you want the results of the query to be made into session variables. do it like this

Code: Select all

$query = "select memid, cbid, coname, firstname, lastname, address, city, state, zip, phone, mememail, otherlink, opfield1, opfield2
             from members where memdir = $memdir";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)){
$_SESSION[memid] = $row[memid];
$_SESSION[cbid] = $row[cbid];
$_SESSION[coname] = $row[coname];
$_SESSION[firstname] = $row[firstname];
//finish all the things you want
}
but make sure you have session_start(); at the top of your page.

Posted: Wed Mar 23, 2005 12:36 pm
by feyd
remember to quote your named array indicies, or string literals..