vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Fatal error while adding users using a script (https://vborg.vbsupport.ru/showthread.php?t=267099)

nainil 07-19-2011 09:45 PM

Fatal error while adding users using a script
 
When I run the below query it tells me:

Array ( [0] => That username is already in use or does not meet the administrator's standards. If you are mcar and you have forgotten your password, click here. ) 0 Failure
hello no newuserid

Fatal error: Registry object is not an object in [path]/includes/class_dm.php on line 205

-------------------------------

If there are errors while registering a user I want the script to ignore them. I don't want the script to stop. I believe the Fatal Error is due to 2 instances of database calls. I am new here so am wondering if someone can help show the right way to get this script correct so it pulls up records from one table and uses them to create users in vbulletin.

PHP Code:

<?php

function register_in_vb($username$password$email)
{
    
define('VB_AREA''External');
    
define('SKIP_SESSIONCREATE'0);
    
define('SKIP_USERINFO'1);
    
//define('CWD', './../../forum/' );
    
require_once('includes/init.php');
    require_once(
'includes/functions_misc.php');

    
$registry $vbulletin
    unset(
$vbulletin); 
    
$vbDb $registry->db
    
//declare as global vbulletin's registry and db objects 
    
global $vbulletin,$db
    
$vbulletin $registry
    
//backup the original $db object (new!!) 
    
$backupdb $db
    
$db $vbDb

    
$newuser =& datamanager_init('User'$vbulletinERRTYPE_ARRAY);
    
$newuser->set('username'$username);
    
$newuser->set('email'$email);
    
$newuser->set('password'$password);
    
$newuser->set('usergroupid'2);
    
    
$newuser->pre_save();
    
    if(empty(
$newuser->errors)){ // success
        
$db $backupdb;
        echo 
1;
        echo 
" Success <br>";
        return 
$newuser->save();
        
    }else{ 
// failure
        
$db $backupdb;
        
print_r$newuser->errors);
        echo 
0;
        echo 
" Failure <br>";        
        return 
false;
    }

}


// For Local Database
$dbhostname "localhost";
$dbusername "dbuser";
$dbpassword "dbpassword";
$dbname "mydb";

$con mysql_connect($dbhostname,$dbusername,$dbpassword); 
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }

mysql_select_db($dbname$con);

$sql "select uname,upwd,uemail from users where delflag=0 and inactive=0 and usertype in (3, 30)";
//echo $sql;

$result mysql_query($sql);

while(
$row mysql_fetch_array($result)) {

$username $row[uname];
$password $row[upwd];
$email $row[uemail];

    
// Add the users to vBulletin
    
$newuserid register_in_vb($username$password$email);
    
    
//    echo "hi ".$newuserid;

    
if(!$newuserid) {
        echo 
"hello no newuserid";
    }

}
// end while
mysql_close($con);

?>


kh99 07-19-2011 10:58 PM

The "That username is already in use..." message probably means the username is already in the database (or it could mean it's a username that isn't allowed), so up to there it looks like things are working as expected. I think you're getting the "Fatal error: Registry object is not an object ..." because the code is depending on including init.php to define $vbulletin, but you've got require_once() so it only works once.

To be honest, I looked at it trying to see how to fix it but I can't understand what's going on. Do you understand why it seems to be trying to replace the existing $vbulletin with a new one?


All times are GMT. The time now is 03:05 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.00943 seconds
  • Memory Usage 1,739KB
  • 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_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)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