nainil
07-19-2011, 09:45 PM
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
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', $vbulletin, ERRTYPE_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);
?>
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
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', $vbulletin, ERRTYPE_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);
?>