PDA

View Full Version : Help with SQL


maximux1
07-19-2006, 11:43 PM
Can anyone help me with what is wrong with this query?

$db->query_first('SELECT userid, usergroupid, membergroupids, username, password, salt FROM user WHERE (username = "$username")')

I'm getting the following error from my script -

Invalid SQL:
SELECT userid, usergroupid, membergroupids, username, password, salt FROM user WHERE username = interpolated_username;

MySQL Error : Unknown column 'interpolated_username' in 'where clause'

Thanks guys,

Max

Alan @ CIT
07-20-2006, 05:52 AM
Try changing it to:

$db->query_first("SELECT userid, usergroupid, membergroupids, username, password, salt FROM " . TABLE_PREFIX . "user WHERE username = '" . $username . "');

Thanks,
Alan.

Code Monkey
07-20-2006, 12:51 PM
Try changing it to:

$db->query_first("SELECT userid, usergroupid, membergroupids, username, password, salt FROM " . TABLE_PREFIX . "user WHERE username = '" . $username . "');
Thanks,
Alan.

You forgot the closing doublequote and there is no reason to concat the $username when the query is wrapped in double quotes.


$db->query_first("SELECT userid, usergroupid, membergroupids, username, password, salt FROM " . TABLE_PREFIX . "user WHERE username = '$username'");

maximux1
07-20-2006, 05:59 PM
Here's my script guys, it's what I would consider pretty basic, but...for whatever reason I just can not get this to work. Im sure I am just overlooking something as I am pretty glazed from working on this. Maybe some fresh eyes can help me...

Here's the script:

// get userid for given username
$db->query_first("SELECT userid, usergroupid, membergroupids, username, password, salt FROM " . TABLE_PREFIX . "user WHERE username = '$username'");

if ($bbuserinfo['password'] != md5(md5($password) . $bbuserinfo['salt']))
{
//bad password
die('0');
}
else
{
//is user activated?
if ( $bbuserinfo['usergroupid'] == 3 || $bbuserinfo['usergroupid'] == 4 )
{
die('0');
}

//is user banned?
if ( $bbuserinfo['usergroupid'] == 8 )
{
die('0');
}

//is the user an admin / super mod?
if ( $bbuserinfo['usergroupid'] == 5 || $bbuserinfo['usergroupid'] == 6 )
{
die('2');
}

//user is regular user
die('1');
}


I've corrected my query to your versions, JumpD - Do you guys see whats wrong here? The problem is that it always reports that the user/pass is incorrect.

Seems simple enough, eh?

Thanks!

Max

Thanks for the help, guys!

I've figured out the problem however. The problem was not with the query that you guys helped with, it was due to the fact that I had not set the query to an array.

Learned a lot from this little excercise, thanks again!

Code Monkey
07-21-2006, 01:22 AM
$bbuserinfo is only available in templates.


$vbulletin->userinfo['password']


Same goes for the usergroup and salt ones as well.