vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Help with SQL (https://vborg.vbsupport.ru/showthread.php?t=121636)

maximux1 07-19-2006 11:43 PM

Help with SQL
 
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:

PHP Code:

$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

Quote:

Originally Posted by Alan @ CIT
Try changing it to:

PHP Code:

$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.

PHP Code:

$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:

PHP Code:

// 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'] == || $bbuserinfo['usergroupid'] == 
        {
            die(
'0');
        }

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

        
//is the user an admin / super mod?
        
if ( $bbuserinfo['usergroupid'] == || $bbuserinfo['usergroupid'] == 
        {
            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.

PHP Code:

$vbulletin->userinfo['password'

Same goes for the usergroup and salt ones as well.


All times are GMT. The time now is 10:45 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01027 seconds
  • Memory Usage 1,737KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete