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? Link to comment https://forums.phpfreaks.com/topic/143922-solved-calling-function-not-working/ 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 Link to comment https://forums.phpfreaks.com/topic/143922-solved-calling-function-not-working/#findComment-755201 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"]; } } Link to comment https://forums.phpfreaks.com/topic/143922-solved-calling-function-not-working/#findComment-755216 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>"; Link to comment https://forums.phpfreaks.com/topic/143922-solved-calling-function-not-working/#findComment-755221 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. Link to comment https://forums.phpfreaks.com/topic/143922-solved-calling-function-not-working/#findComment-755234 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); Link to comment https://forums.phpfreaks.com/topic/143922-solved-calling-function-not-working/#findComment-755240 Share on other sites More sharing options...
aebstract Posted February 5, 2009 Author Share Posted February 5, 2009 White page with user not found. Link to comment https://forums.phpfreaks.com/topic/143922-solved-calling-function-not-working/#findComment-755242 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 Link to comment https://forums.phpfreaks.com/topic/143922-solved-calling-function-not-working/#findComment-755247 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. Link to comment https://forums.phpfreaks.com/topic/143922-solved-calling-function-not-working/#findComment-755251 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.