Jump to content


Photo

Retrieve Session Value


  • Please log in to reply
4 replies to this topic

#1 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 06 June 2006 - 01:04 PM

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?

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...

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

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 01:35 PM

$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.

Info: PHP Manual


#3 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 06 June 2006 - 01:47 PM

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)

#4 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 06 June 2006 - 01:58 PM

Nevermind - placed '' around $sun in the query and I think its working

#5 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 02:22 PM

Post again if you still have issues.

Info: PHP Manual





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users