vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   How do i get the userid from the username? (https://vborg.vbsupport.ru/showthread.php?t=61558)

killervette 02-14-2004 08:27 PM

How do i get the userid from the username?
 
What is the easiest way to get a userid based on the username in php script? thanks.

assassingod 02-14-2004 08:29 PM

The query would be:
PHP Code:

SELECT userid
FROM user
WHERE username 
'xxx' 

xxx being the username

MindTrix 02-14-2004 08:29 PM

Could you explain a bit more please mate?

MindTrix 02-14-2004 08:30 PM

ah ok :)

killervette 02-14-2004 08:46 PM

How do you connect to the database??

assassingod 02-14-2004 08:50 PM

Use a script like this:
PHP Code:

<?php
error_reporting
(E_ALL & ~E_NOTICE);
require_once(
'./global.php');
$getuser $DB_site->query("
 SELECT userid,username
 FROM user
 WHERE username = 'admin'
"
);
$user $DB_site->fetch_array($getuser);
echo(
"The userid for $user[username] is <b>$user[userid]</b>");
?>

xxx being the username

Andreas 02-14-2004 08:51 PM

PHP Code:

$link mysql_connect('host''username''password') or die('Could not connect to mySQL-server');
mysql_select_db('vbdb'$link) or die('Could not select vBulletin database'); 

'host' and so on must be replaced by the actual values of course.

killervette 02-14-2004 09:00 PM

neither worked??

assassingod 02-14-2004 09:01 PM

Save mine as script.php and upload it to your forums directory and then go youforums.com/script.php. It should work

killervette 02-14-2004 09:04 PM

This page is not gonna be in the forum directory.

killervette 02-14-2004 09:05 PM

The result for the script echos this "The userid for is ". I specify a username that exists case sensitive.

assassingod 02-14-2004 09:06 PM

It should still work if you replace
PHP Code:

require("./global.php"); 

with

PHP Code:

chdir("YOUR forum directoru");
require(
"./global.php"); 


assassingod 02-14-2004 09:10 PM

Quote:

Originally Posted by killervette
The result for the script echos this "The userid for is ". I specify a username that exists case sensitive.

Recheck my script, I missed out a $. It works perfectly now, ive tested it:)

Sorry!:)

killervette 02-14-2004 10:15 PM

I put

chdir("/mainforum/");
require("./global.php");

i have the file in the root and my directory is mainforum

Andreas 02-14-2004 10:18 PM

The directory is REALLY /mainforum?
I doubt that ... except you are in a chroot-jail.
More likely it is smt.h like /var/htdocs/youraccount/html/mainforum

Quarterbore 05-06-2006 09:53 PM

I have a situation where I also need to convert a USERNAME from a template to a USERID inside a main php file....

I tried to use the code above in my file like this:

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 would really appreciate any help!

bairy 05-10-2006 07:39 PM

you can use
PHP Code:

$user $vbulletin->db->query_first("SELECT userid FROM user WHERE username = '$username

(You were missing the ' to surround $username, but query_first does it all in one for you anyway.)

$user['userid'] will then contain the userid

Marco van Herwaarden 05-16-2006 08:45 AM

Can we please keep vB3.5 questions and solutions in the vB3.5 forum. This to avoid confusion.


All times are GMT. The time now is 04:50 PM.

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.01260 seconds
  • Memory Usage 1,756KB
  • 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
  • (6)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (18)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