Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,646 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,107 people online right now. Registration is fast and FREE... Join Now!




Input existing table info into second table - help with snippet

 
Reply to this topicStart new topic

Input existing table info into second table - help with snippet

King8654
post 16 Aug, 2008 - 09:43 AM
Post #1


D.I.C Head

Group Icon
Joined: 4 Mar, 2008
Posts: 91


My Contributions


Hey yall, I have subscriberinfo, which is the table that has all my sites users, from day one. this is up to 246. Around member 150 or so, i changed over the reg process to phpbb3, as well as login and sessions. When the user regs, it inputs the id, username, email, password into both tables, but Unfort, the first 150 users are not in the phpbb3 phpbb_users table. I have this code to transfer accounts which are not in phpbb_users into its table from subscriberinfo, but upon executing the php(its migrate.php, so is the correct way hxxp://www.mysite.com/migrate.php?)

CODE

    <?php
    define('IN_PHPBB', true);
    $phpbb_root_path = './forum/';     //Path to forum
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);
    include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();

    // Retrieve default group ID
    $sql = 'SELECT group_id
        FROM ' . GROUPS_TABLE . "
        WHERE group_name = '" . $db->sql_escape('REGISTERED') . "'
            AND group_type = " . GROUP_SPECIAL;
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);

    if (!sizeof($row))
    {
        trigger_error('NO_GROUP');
    }
    $group_id = (int) $row['group_id'];

    // Get the old users
    $sql = 'SELECT user_id, email, password, username
            FROM subscriberinfo
            ORDER BY user_id DESC';

    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrowset($result);
    $db->sql_freeresult($result);

        // Create new accounts for them
    foreach($row as $existing)
    {
        //Data validation
        $error = validate_data($row[$i], array(
            'username'            => array(
                array('string', false, $config['min_name_chars'], $config['max_name_chars']),
                array('username', '')),
            'password'            => array(
                array('string', false, $config['min_pass_chars'], $config['max_pass_chars']),
                array('password')),
            'email'                => array(
                array('string', false, 6, 60),
                array('email')),
        ));
        
        if (!sizeof($error))
        {
            $data = array(
                'username'            => utf8_normalize_nfc($existing['username']),
                'user_password'        => phpbb_hash($existing['password']),
                'user_email'        => strtolower($existing['email']),
                'group_id'            => $group_id,
                'user_type'            => USER_NORMAL,
            );
            
            $user_id = user_add($data);

            if ($user_id === false)
            {
                echo 'User: ' . $existing['username'] . ' failed to transfer<br />';
            }
            else
            {
                echo 'User: ' . $existing['username'] . ' (' . $user_id . ') added to phpBB successfully<br />';
            }
        }
    }
    ?>


I had to manually delete the username_clean index key from the table so accounts with no username present could still be transferred, and a username be chosen via account panel on site.

This post has been edited by King8654: 16 Aug, 2008 - 09:45 AM
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 16 Aug, 2008 - 09:45 AM
Post #2


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,933



Thanked 118 times

Dream Kudos: 8525

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


Moved to PHP smile.gif
User is offlineProfile CardPM

Go to the top of the page

King8654
post 16 Aug, 2008 - 09:56 AM
Post #3


D.I.C Head

Group Icon
Joined: 4 Mar, 2008
Posts: 91


My Contributions


LoL, dont think ive ever posted a topic in the right category. thanks for another swap ha
User is offlineProfile CardPM

Go to the top of the page

King8654
post 16 Aug, 2008 - 07:21 PM
Post #4


D.I.C Head

Group Icon
Joined: 4 Mar, 2008
Posts: 91


My Contributions


nvm worked with one of phpbb3 mods and with lil modification of the script got it to work like beauty...thanks
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 04:43AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month