Mark Lyons
Mark Lyons

Reputation: 1422

Trying to pull user ID from database given username, what's wrong with this MySQL query?

$username is the, well, username of the logged in user.

$username_query = mysql_query("SELECT userid from registerusers WHERE username = '$username'");
$username_id = mysql_fetch_row($username_query);

I'm trying to use $username_id in another query and am testing by printing out in a page, and it always returns 'Array'. I'm really bad with MySQL and most of the research I've done has yielded overcomplicated responses and I'd just like to get a response specific to my problem so I really understand this, so I'm sorry if this is deemed a 'bad' question.

Upvotes: 0

Views: 123

Answers (2)

Aurelio De Rosa
Aurelio De Rosa

Reputation: 22152

You should use $username_id[0] in the other query.

Upvotes: 1

Marc B
Marc B

Reputation: 360602

mysql_fetch_*() functions return an array or object, representing the entire ROW of data you've fetched, even if that row consists of a single value.

Your user id value will actually be $username_id[0]

Upvotes: 1

Related Questions