sstangle73 Posted September 4, 2007 Share Posted September 4, 2007 on my site i have it do a query at the top of everypage with several other functions: <?php session_start(); include("database.php"); include("login.php"); include("func.php"); mait(); query($_SESSION['ID']); PageTop($level, $ID, $username, $color); ?> now later down the index i call for this <?php if($logged_in){ echo "Welcome " . $name . "<br>"; echo "Logged in as " . $username . " ID Number: " . $ID . " <a href=\"logout.php\">logout</a><br>"; echo "Your registered email is " . $email . "<br>"; echo "Your birthday is " . $bdate . "<br>"; echo "You are " . $age . " years old <br>"; echo "You are " . $sex . "<br>"; echo "You live in " . $location . "<br>"; ?> for the age and location it comes up blank. also on a different page $profile comes up blank heres the query: <?php function query($ID){ $query="SELECT * FROM users WHERE ID = '$ID' LIMIT 1"; $result=mysql_query($query); while($array=mysql_fetch_assoc($result)){ $level=$array['level']; $ID=$array['ID']; $user=$array['username']; $name=$array['name']; $dname=$array['dname']; $email=$array['email']; $bdate=$array['bdate']; $sex=$array['sex']; $city=$array['city']; $state=$array['state']; $schedule=$array['schedule']; $color=$array['color']; $quote=$array['quote']; } $age=birthday($bdate); $location="" . $city . ", " . $state . ""; $query2="SELECT * FROM profile WHERE ID = '$ID' LIMIT 1"; $result2 = mysql_query($query2); while($array2=mysql_fetch_assoc($result2)){ $about=$array2['about']; } } ?> thanks! Quote Link to comment https://forums.phpfreaks.com/topic/67920-solved-help/ Share on other sites More sharing options...
trq Posted September 4, 2007 Share Posted September 4, 2007 You either need to make all those variables within your function global (the bad way). Or return an array with all the data you want, then use that later in your page. Variables contained within a function are not accessable outside the functions scope by default. Quote Link to comment https://forums.phpfreaks.com/topic/67920-solved-help/#findComment-341378 Share on other sites More sharing options...
sstangle73 Posted September 4, 2007 Author Share Posted September 4, 2007 why would some work then? Quote Link to comment https://forums.phpfreaks.com/topic/67920-solved-help/#findComment-341380 Share on other sites More sharing options...
trq Posted September 4, 2007 Share Posted September 4, 2007 They wouldn't. Quote Link to comment https://forums.phpfreaks.com/topic/67920-solved-help/#findComment-341383 Share on other sites More sharing options...
sstangle73 Posted September 4, 2007 Author Share Posted September 4, 2007 nvm i just got what you said. what about the 2nd query?> Quote Link to comment https://forums.phpfreaks.com/topic/67920-solved-help/#findComment-341385 Share on other sites More sharing options...
trq Posted September 4, 2007 Share Posted September 4, 2007 What about it? Any variables within a function only exist within the function. PS: You also don't need any while() loops if your only retrieving one row of data. Quote Link to comment https://forums.phpfreaks.com/topic/67920-solved-help/#findComment-341386 Share on other sites More sharing options...
sstangle73 Posted September 4, 2007 Author Share Posted September 4, 2007 i can call all theese set vars $level $ID $user $name $dname $email $bdate $sex $city $state $schedule $color $quote but not $about in a second query?> ill be adding more then one line later tthats why while is there Quote Link to comment https://forums.phpfreaks.com/topic/67920-solved-help/#findComment-341389 Share on other sites More sharing options...
trq Posted September 4, 2007 Share Posted September 4, 2007 If you have access to those variables, they are not comming from that function. Quote Link to comment https://forums.phpfreaks.com/topic/67920-solved-help/#findComment-341391 Share on other sites More sharing options...
sstangle73 Posted September 4, 2007 Author Share Posted September 4, 2007 can $_SESSION['about'] be called by $about? Quote Link to comment https://forums.phpfreaks.com/topic/67920-solved-help/#findComment-341393 Share on other sites More sharing options...
wildteen88 Posted September 4, 2007 Share Posted September 4, 2007 can $_SESSION['about'] be called by $about? only if register_globals is enabled. register_globals is now depreciated and is disabled by default as it can cause security exploits within your code. However some hosts do still keep this setting enabled for compatibility reasons for older (outdated) scripts. Quote Link to comment https://forums.phpfreaks.com/topic/67920-solved-help/#findComment-341417 Share on other sites More sharing options...
sstangle73 Posted September 4, 2007 Author Share Posted September 4, 2007 thats why it was confuseing the shit out of me ah i guess i wont use a function thanks you 2 Quote Link to comment https://forums.phpfreaks.com/topic/67920-solved-help/#findComment-341439 Share on other sites More sharing options...
wildteen88 Posted September 4, 2007 Share Posted September 4, 2007 thats why it was confuseing the shit out of me ah i guess i wont use a function thanks you 2 Whats register_globals to do with not using your function? Quote Link to comment https://forums.phpfreaks.com/topic/67920-solved-help/#findComment-341470 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.