Jump to content

Archived

This topic is now archived and is closed to further replies.

master82

Retrieve Session Value

Recommended Posts

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

Share this post


Link to post
Share on other sites
$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.

Share this post


Link to post
Share on other sites
I now get...

Unknown column '$sun' in 'where clause'

Sorry, put "" around the SELECT ----> $sun

then got...

Unknown column 'master82' in 'where clause'


(master82 being the stored value)

Share this post


Link to post
Share on other sites
Nevermind - placed '' around $sun in the query and I think its working

Share this post


Link to post
Share on other sites
Post again if you still have issues.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.