vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Can someone help me with this script? (https://vborg.vbsupport.ru/showthread.php?t=71599)

Takamine334 11-11-2004 05:25 AM

Can someone help me with this script?
 
PHP Code:

<?



function  dbconnect($mysql_host, $mysql_user, $mysql_pass,$mysql_db)
{
global $link ;
 $link = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
    if (!$link) return false ;
   $select =    mysql_select_db($mysql_db);
   if (!$select) return false;
   return true ;
}

function get_date_time($timestamp = 0)
{
  if ($timestamp)
    return date("Y-m-d H:i:s", $timestamp);
  else
    return gmdate("Y-m-d H:i:s");
}

echo "<center><font size=8><b><u>Users Import Script</u></b></font></center><hr>";
echo "This script will now import all users from Vbulletin forum into the database of the tracker !<br>";
echo "If you see any error message, check your config.php files and put the right parameters inside.<hr>" ;

require_once("config.php");

if ( dbconnect($mysql_host, $mysql_user, $mysql_pass,$mysql_db) )
{
echo "<li>Connection to SQL database was a success</li>";

$res = mysql_query("SELECT username,password,email FROM ".$tableprefix."user")  ;

if ($res) {
echo "<li>Connection to Vbulletin users list was a success !</li>";
while ($dat=mysql_fetch_array($res))
{
echo "<br>Now adding: <font color=green>".$dat['username']."</font> into tracker users list";

         $rz = mysql_query("INSERT INTO users (username, password,  email, status, added) VALUES
         ('" . $dat['username'] . "',
         '" . $dat['password'] . "',
        '" . $dat['email'] . "',
          'confirmed' ,'" . get_date_time() . "' )
          ");
        $userid2 = mysql_insert_id();
echo "with id : <font color=green>".$userid2."</font> .";
 if (!$rz) {
      echo "<br><font color=red>An error occured :</font> ";
      if (mysql_errno() == 1062)
        echo "Username already exists!";
    }

}
}
else echo "<li>Cannot retrieve Vbulletin users list !</li>";
}
else echo "<li>Connection to SQL database failed</li>";

?>

What this script does is adds users from the USER table and puts them in a table called USERS. It's for a Bit Torrent tracker page.

The problem is it pulls the users in numerical order and adds them.
Example:

Table USER
INSERT INTO `user` VALUES (1,6,'',0,'Admin',
INSERT INTO `user` VALUES (2,2,'',0,'smssf',
INSERT INTO `user` VALUES (3,2,'',0,'tcort','
INSERT INTO `user` VALUES (4,2,'',0,'AtEaseWeb.com Kids Suck!',
INSERT INTO `user` VALUES (5,2,'',0,'thebigguy','
INSERT INTO `user` VALUES (1668,3,'',0,'nemo45',
INSERT INTO `user` VALUES (7,2,'',0,'luvdmb36',
INSERT INTO `user` VALUES (8,2,'',0,'Cole','
INSERT INTO `user` VALUES (9,2,'',0,'roach',

notice the user nemo45 with USERID of 1668

once the script is run to add the users, here's what I get:


Table USERS
INSERT INTO `users` VALUES (1,'Admin',
INSERT INTO `users` VALUES (2,'smssf',
INSERT INTO `users` VALUES (3,'tcort',
INSERT INTO `users` VALUES (4,'AtEaseWeb.com Kids Suck!',
INSERT INTO `users` VALUES (5,'thebigguy',
INSERT INTO `users` VALUES (6,'nemo45',
INSERT INTO `users` VALUES (7,'luvdmb36',
INSERT INTO `users` VALUES (8,'Cole',
INSERT INTO `users` VALUES (9,'roach',

Now notice nemo45

Since Nemo45 is the 6th user added, it gave it USERID 6 instead of USERID 1668.

This is a bug that will show wrong users on my Vbulletin website when they post music files. Can someone please edit this script so that it pulls the correct USERID in table USER and puts it in table USERS?

Logikos 11-11-2004 05:49 AM

Your code is very sloppy and i suggest you read up on something called whitespace. Anyways, try using the addslashes() function inside the insert query.

Takamine334 11-11-2004 01:35 PM

I didn't write this code and I don't know much about PHP...I wish I did. I guess I could read up on whitespaces, but I dont' think that will help much as I've never had any formal training on PHP coding.

Takamine334 11-11-2004 11:28 PM

no one? Hmm, I thought this was a forum where people knew php...guess not. oh well.

AN-net 11-12-2004 02:16 AM

you should use $DB_site variable for connecting with the vb database and if the table USERS is in the same database use $DB_site again;) You can also just copy the user table from database to another, rename it, add/drop/edit fields and your done:)

Takamine334 11-12-2004 02:38 AM

Quote:

Originally Posted by AN-net
you should use $DB_site variable for connecting with the vb database and if the table USERS is in the same database use $DB_site again;) You can also just copy the user table from database to another, rename it, add/drop/edit fields and your done:)

can you show me what you're talking about? I'll even pay you to write the code out correctly.

AN-net 11-12-2004 03:02 AM

Quote:

Originally Posted by Takamine334
can you show me what you're talking about? I'll even pay you to write the code out correctly.

if your using phpmyadmin go to the user table, click the operations tab.


if the USERS table is in a separate database then vb, use "Copy table to (database.table):" fill in the name of the database the USERS table is in and the name of the new table and choose "structure and data only."'

if its in the same database then still use "Copy table to(database.table)" and select your vb's database and a new name for the copy table and select "structure and data only."

after that alter the new copied table until it looks like the USERS table;)

Logikos 11-12-2004 03:26 AM

Quote:

Originally Posted by Takamine334
no one? Hmm, I thought this was a forum where people knew php...guess not. oh well.

Post like that kinda gets on my nerves. When posting help, give people some time. Not everyone is on at the same time as you are. In any case your query should look something like this.

PHP Code:

        $rz $DB_site->query("
                INSERT INTO " 
TABLE_PREFIX "users
                        (username, password,  email, status, added)
                VALUES
                        (
                                '" 
addslashes($dat['username']) . "',
                                '" 
addslashes($dat['password']) . "',
                                '" 
addslashes($dat['email']) . "',
                                'confirmed',
                                '" 
get_date_time() . "'
                        )
        "
); 


AN-net 11-12-2004 03:56 AM

livewires query will only work if your using the same database as vb;)

Takamine334 11-12-2004 04:00 AM

deleted post


All times are GMT. The time now is 04:34 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.01836 seconds
  • Memory Usage 1,757KB
  • 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
  • (2)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete