envexlabs Posted June 21, 2007 Share Posted June 21, 2007 Hey, I have 2 files, index.php and functions.php in index.php <?php if ($au=$_SESSION['_amember_user']){ // user is logged-in print "<p>Hello $au[name_f] $au[name_l]!</p><br>"; print "<a href='/amember/logout.php'>Logout</a>"; } else { // user is not logged-in print '<p>Hello!</p> <a href="javascript:login_fade();">Login</a>'; }?> display_nav(); in functions.php function display_nav(){ $nav_display = mysql_query('SELECT * FROM `amember_payments` WHERE `member_id` = "' . $au[member_id] . '"'); $nav = mysql_fetch_row($nav_display); //renders out the navigation depending on the user if($nav[2] == 1) { //user user_nav(); } elseif($nav[2] == 2 || $nav[2] == 3) { //store store_nav(); } else{ //guest } } I have included the functions.php in index.php, but for some reason display_nav(); doesn't work. If i copy the function into index.php it works. Why are my variables from index.php not working in function.php even though function.php is included in index.php Any help is appreciated! Thanks. Link to comment https://forums.phpfreaks.com/topic/56622-solved-variables-and-functions-in-different-files/ Share on other sites More sharing options...
Orio Posted June 21, 2007 Share Posted June 21, 2007 Put the call to the function between <?php and ?>... Orio. Link to comment https://forums.phpfreaks.com/topic/56622-solved-variables-and-functions-in-different-files/#findComment-279596 Share on other sites More sharing options...
envexlabs Posted June 21, 2007 Author Share Posted June 21, 2007 hey, i tried that. the problem is $au[member_id] isn't being recognized in functions.php Link to comment https://forums.phpfreaks.com/topic/56622-solved-variables-and-functions-in-different-files/#findComment-279600 Share on other sites More sharing options...
Orio Posted June 21, 2007 Share Posted June 21, 2007 if ($au=$_SESSION['_amember_user']) Should be if ($au==$_SESSION['_amember_user']) Maybe that'll fix the problem. Orio. Link to comment https://forums.phpfreaks.com/topic/56622-solved-variables-and-functions-in-different-files/#findComment-279602 Share on other sites More sharing options...
envexlabs Posted June 21, 2007 Author Share Posted June 21, 2007 hey, the variable has been set and is recognized in index.php it is not recognized in functions.php, which is the problem i am trying to fix. Link to comment https://forums.phpfreaks.com/topic/56622-solved-variables-and-functions-in-different-files/#findComment-279603 Share on other sites More sharing options...
Orio Posted June 21, 2007 Share Posted June 21, 2007 Oh of course lol It's a scope issue- $au is in the global scope... To solve this, add in the first line of the function: global $au; Orio. Link to comment https://forums.phpfreaks.com/topic/56622-solved-variables-and-functions-in-different-files/#findComment-279610 Share on other sites More sharing options...
envexlabs Posted June 21, 2007 Author Share Posted June 21, 2007 worked like a charm. thanks. Link to comment https://forums.phpfreaks.com/topic/56622-solved-variables-and-functions-in-different-files/#findComment-279613 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.