master82 Posted June 6, 2006 Share Posted June 6, 2006 I have a session created that stores the username, how do I get this from the session and place it into a variable that I can use?[code]include("connect.php");$sun = $_session['username'];$sql = SELECT * FROM users WHERE username = $sun;$result = mysql_query($sql, $conn) or die(mysql_error());while ($newArray = mysql_fetch_array($result)) {etc...[/code]This is what I currently have, (Session_start() already called earlier in the code), How can I retrieve the 'username' value and use it in my SQL query?Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/11323-retrieve-session-value/ Share on other sites More sharing options...
ober Posted June 6, 2006 Share Posted June 6, 2006 $sun = $_SESSION['username'];That should work (make sure you use CAPS). Remember that you must have put $_SESSION['username'] = 'some_value'; somewhere else in your code. Quote Link to comment https://forums.phpfreaks.com/topic/11323-retrieve-session-value/#findComment-42404 Share on other sites More sharing options...
master82 Posted June 6, 2006 Author Share Posted June 6, 2006 I now get...Unknown column '$sun' in 'where clause'Sorry, put "" around the SELECT ----> $sunthen got...Unknown column 'master82' in 'where clause'(master82 being the stored value) Quote Link to comment https://forums.phpfreaks.com/topic/11323-retrieve-session-value/#findComment-42407 Share on other sites More sharing options...
master82 Posted June 6, 2006 Author Share Posted June 6, 2006 Nevermind - placed '' around $sun in the query and I think its working Quote Link to comment https://forums.phpfreaks.com/topic/11323-retrieve-session-value/#findComment-42412 Share on other sites More sharing options...
ober Posted June 6, 2006 Share Posted June 6, 2006 Post again if you still have issues. Quote Link to comment https://forums.phpfreaks.com/topic/11323-retrieve-session-value/#findComment-42418 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.