aebstract Posted February 5, 2009 Share Posted February 5, 2009 function grabMemDetails (){ global $db; $result = mysql_query("SELECT * FROM p_users WHERE id='$_SESSION[id]'") or DIE(mysql_error()); while($r=mysql_fetch_array($result)) { $email=$r["email"]; $firstname=$r["firstname"]; $lastname=$r["lastname"]; $address=$r["address"]; $city=$r["city"]; $state=$r["state"]; $zip=$r["zip"]; $phone=$r["phone"]; $pwhint=$r["pwhint"]; $baddress=$r["baddress"]; $bstate=$r["bstate"]; $bcity=$r["bcity"]; $bzip=$r["bzip"]; $companyid=$r["companyid"]; $middleinitial=$r["middleinitial"]; $registerdate=$r["registerdate"]; } } <?php session_start(); header("Cache-control: private"); if(!isset($_SESSION["id"])) { header("Location: index.php?page=login"); } grabMemDetails(); $content .= "<div id=\"full_content\"> <p>Welcome, $firstname $lastname</p> </div>"; ?> $firstname and $lastname are not displaying, any idea why? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 5, 2009 Share Posted February 5, 2009 read up on variable scope: http://us3.php.net/variables.scope Quote Link to comment Share on other sites More sharing options...
aebstract Posted February 5, 2009 Author Share Posted February 5, 2009 Should this not work? function grabMemDetails (){ global $db; $result = mysql_query("SELECT * FROM p_users WHERE id='$_SESSION[id]'") or DIE(mysql_error()); global $email, $firstname, $lastname, $addres, $city, $state, $zip, $phone, $cell, $pwhint, $baddress, $bstate, $bcity, $bzip, $companyid, $middleinitial, $registerdate; while($r=mysql_fetch_array($result)) { $email=$r["email"]; $firstname=$r["firstname"]; $lastname=$r["lastname"]; $address=$r["address"]; $city=$r["city"]; $state=$r["state"]; $zip=$r["zip"]; $phone=$r["phone"]; $cell=$r["cell"]; $pwhint=$r["pwhint"]; $baddress=$r["baddress"]; $bstate=$r["bstate"]; $bcity=$r["bcity"]; $bzip=$r["bzip"]; $companyid=$r["companyid"]; $middleinitial=$r["middleinitial"]; $registerdate=$r["registerdate"]; } } Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 5, 2009 Share Posted February 5, 2009 it might work...but that is a horrible way of doing it. why not something MUCH simpler like this: function grabMemDetails (){ global $db; $result = mysql_query("SELECT * FROM p_users WHERE id='$_SESSION[id]' LIMIT 1") or DIE(mysql_error()); return mysql_fetch_assoc($result); } $details = grabMemDetails(); $content .= "<div id=\"full_content\"> <p>Welcome, {$details['firstname']} {$details['lastname']}</p> </div>"; Quote Link to comment Share on other sites More sharing options...
aebstract Posted February 5, 2009 Author Share Posted February 5, 2009 Changed to the way you showed and it still won't echo any results. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 5, 2009 Share Posted February 5, 2009 what does this output: function grabMemDetails (){ global $db; $result = mysql_query("SELECT * FROM p_users WHERE id='$_SESSION[id]' LIMIT 1") or DIE(mysql_error()); if(!mysql_num_rows($result)) die("User not found"); return mysql_fetch_assoc($result); } $details = grabMemDetails(); print_r($details); Quote Link to comment Share on other sites More sharing options...
aebstract Posted February 5, 2009 Author Share Posted February 5, 2009 White page with user not found. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 5, 2009 Share Posted February 5, 2009 so, the session hasn't been started with session_start(), $_SESSION['id'] is empty or $_SESSION['id'] is not a valid id from p_users Quote Link to comment Share on other sites More sharing options...
aebstract Posted February 5, 2009 Author Share Posted February 5, 2009 The session id is set, I logged out and back in and the variables showed up, I browsed around and went back and it had the same error. I echoed the id and it had gone from its start point of 1 to 5 by time I got back to the page. I just have to look around and see what is making it increase. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.