Select one cells contents by supplying another cells contents..<

liunx

Guest
I have usernames stored in the database. A logged in users name is displayed via $_SESSION['username']. What I've tried to do is get the userid from this by doing the following:

$query1="SELECT userid FROM users WHERE username={$_SESSION['username']}";

But this doesn't seem to work - it just comes up blank.try this
$query1="SELECT userid FROM users WHERE username='{$_SESSION['username']}'";

after your mysql_query function you should ad or die(mysql_error());When I try to display the $query1 variable all that is displayed is - SELECT userid FROM users WHERE username='the persons username is here'

How do I extract the userid from this?I've been searching for ages, and I don't know why I can't find out how to do this. I'm sure it's very simple, but I don't really know much php, so could someone help me out?I'm confusd, I thought that was what you wanted..?Sounds like your not actually running the query. All that code does is create the query string. You then need to call a function to interpret it. Here's a standard template to run a query:mysql_connect("localhost", "username", "password") or die(mysql_error()); //connect
mysql_select_db("database"); //select the database
$query1="SELECT userid FROM users WHERE username='{$_SESSION['username']}'";
$result = mysql_query($query1) or die(mysql_error()); //runs the query
$row = mysql_fetch_array($result); //gets the row info
$userid = $row["userid"]; //get the idThanks IKLOP, thats just what I needed!
 
Back
Top