Log in

View Full Version : How to get username from vbb db?


bensin
05-26-2003, 04:31 PM
I have the proper db connect stuff all lined up, but the db refuses to spit data back at me. On my front page i have a login form and it auths against the vbb user info by way of a hack found here - works great. Then when the user visits after having the login cookie set, I want to print 'Welcome back $username' where the form would be. 'Welcome back ' shows but not the username i'm shooting for. That all works great, but for the life of me (and maybe i'm missing something simple) but I cant seem to pull data from the 'user' table of my vbb dbase. My query is $result=mysql_query("SELECT 'username' FROM 'user' WHERE userid='$bbuserid'"); The variable $bbuserid is set at the top of the php when it checks the cookies, so that works (and with myself logged-in, results with '2', my correct userid). How can I pull this user data from the database, or is there an easier way? I have a very customized login form that integrates with the site design so I'd rather not have to settle for the default vbb login.

filburt1
05-26-2003, 04:43 PM
$result = mysql_query("SELECT username FROM user WHERE userid = $bbuserid");
$user = mysql_fetch_array($result);
$username = $user['username'];

bensin
05-26-2003, 04:55 PM
ahh thanks, my eyesight is going, only difference i can see is that i used " -> $username = $user["username"];

kept telling me mysql_fetch_array wasnt a supported call

mr e
05-26-2003, 11:52 PM
Hey filb, how come you have to use mysql_fetch_array? Shouldn't it only return one entry anyways?

filburt1
05-27-2003, 12:27 AM
mysql_query() always returns a handle. vB's wrapper class simplifies things with query_first() which:
1. Gets the result handle
2. Calls mysql_fetch_array
3. Returns the first row