
August 31st, 2005
01:42 AM
Neverside Newbie
Status: Offline!
Sessions...and crap.
Hi.
I am currently trying to select something kind of like this:
<?php
SELECT points FROM users WHERE username='$username'
?>
Except the username variable is registered in a session. How can I select points from users where username='$the_username_that_they_logged_into_sessions'? I am using sessions for the member system so I need to select stuff from the db.
Understand? Heh... Basically, how would the query look if I am trying to select something using a variable from sessions?
EDIT: To explain myself further, just as a little extra note, I need to turn the username used in the session into something I can use in a MySQL query. Hopefully you get now what I am trying to do.
Last edited by Aki, August 31st, 2005 01:50 AM (Edited 1 times)

August 31st, 2005
02:13 AM
Web Developer & Geek
Status: Offline!
If you have stored the username as a session variable then you should be able to just use:
SELECT points FROM users WHERE username=$_SESSION['username']
___________________


August 31st, 2005
02:16 AM
Neverside Newbie
Status: Offline!
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/virtual/site6/fst/var/www/html/akipets/welcomeback.php on line 34
Line 34 is:
<?php
$query = "SELECT points FROM users WHERE username=$_SESSION['username']";
?>

August 31st, 2005
02:36 AM
thinking of something witty to put here
Status: Offline!
You can also use the complex syntax (PHP's name for it):
<?php
$query = "SELECT points FROM users WHERE username = '{$_SESSION['username']}'";
?>

August 31st, 2005
02:40 AM
Neverside Newbie
Status: Offline!
Yay, no more ugly parse errors
<?php
$query = "SELECT points FROM users WHERE username = '{$_SESSION['username']}'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
{
echo ''.$row['points'].'';
}
?>
There is the coding. But it's not echoing or displaying the points row. How can I fix this. I need it to display the row 'points.'
By the way, it's not pulling it up now because the 'username' isn't my primary column. Is there a possible why I can make it select by 'username' column? I heard you could make a column a 'special column' or something? Or maybe I just have to change and register the user id in the session. I don't know.
EDIT: Okay I got it to select by userid! Just register the userid in the session variable whatever... *can't talk in programming language*
PROBLEM SOLVED. THANKS SO MUCH.
Last edited by Aki, August 31st, 2005 02:50 AM (Edited 2 times)