vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   How do I get the userid from the username? (https://vborg.vbsupport.ru/showthread.php?t=114950)

Quarterbore 05-06-2006 10:04 PM

How do I get the userid from the username?
 
I have a script that I want to be able to convert an entered username (in $username) to the userid (in $userid).

I found an old thread for vb 3.0 here:

https://vborg.vbsupport.ru/showthread.php?t=61558

I tried to use the code suggested in there as follows:


Code:

$getuser = $vbulletin->db->query("
 SELECT userid,username
 FROM myuser
 WHERE username = $username
");
$user = $DB_site->fetch_array($getuser);
echo("The userid for $user[username] is <b>$user[userid]</b>");

I know my post is getting the correct $username into this but I am getting a MYSQL error that says...

Quote:

Database error in vBulletin 3.5.2:

Invalid SQL:

SELECT userid,username
FROM XXXXXXXXXX
WHERE username = Quarterbore;

MySQL Error : Unknown column 'Quarterbore' in 'where clause'
Error Number : 1054
Date : Saturday, May 6th 2006 @ 05:17:49 PM
Script : http://www.XXXXXXXXXX.com/XXXXXXXXXX.php
Referrer : http://www.XXXXXXXXXX.com/XXXXXXXXXX.php?do=ad&id=50
IP Address : XXX.XXX.XXXX
Username : Quarterbore
Classname : vb_database
I just can't finish my minor addition until I can get this basic change of $username into $userid

I really do appreciate any help as I have tried all kinds of combinations for the past 4-hrs or more and I am just stumped...

derekivey 05-07-2006 01:44 AM

You could try this:

PHP Code:

$getuser $db->query_read("SELECT userid FROM user WHERE username='".$db->escape_string($username)."'");
$user $db->fetch_array($getuser);
echo(
"The userid for $username is <b>$user[userid]</b>"); 


Quarterbore 05-07-2006 12:02 PM

Thank You!!! That worked... back to my hack!

:banana: ;) :banana:

derekivey 05-07-2006 03:42 PM

No Problem :)

Quarterbore 05-11-2006 04:14 PM

Quote:

Originally Posted by derekivey
You could try this:

PHP Code:

$getuser $db->query_read("SELECT userid FROM user WHERE username='".$db->escape_string($username)."'");
$user $db->fetch_array($getuser);
echo(
"The userid for $username is <b>$user[userid]</b>"); 


If I may ask for more help, how can I put a reality check into this to verify that the value in $username matches something that is in the database? As it is now, if there is a typo the server generates a MYSQL error.

derekivey 05-11-2006 06:42 PM

PHP Code:

$getuser $db->query_read("SELECT userid FROM user WHERE username='".$db->escape_string($username)."'");
$num_users $db->num_rows($getuser);

if (
$num_users == 1)
{
     
$user $db->fetch_array($getuser); 
     echo(
"The userid for $username is <b>$user[userid]</b>");
}
else
{
     echo(
"The Username Does Not Exist");


Try that, let me know if you have any problems.

Thanks,

Derek


All times are GMT. The time now is 01:18 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.01179 seconds
  • Memory Usage 1,734KB
  • 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
  • (1)bbcode_code_printable
  • (3)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)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