Using integrate_register to copy username to second database

Started by Alanar, September 25, 2015, 04:33:48 PM

Previous topic - Next topic

Alanar

So I have the following code and I'm relatively new to PHP, but I'm even newer to using smf functions and the like. I just want to use the integrate_register hook to capture the "realName" variable from the $regOptions array once a user has registered and insert it into the second table as well as the smf_members table. This is so I can join tables in queries and don't have to add columns to the smf_members table for various uses.

Right now I get "Fatal error: Function name must be a string in \path\to\CopyMemberData.php on line 9".

I just need to know what I'm doing wrong at this point.

<?php
if (!defined('SMF'))
die('Hacking attempt...');

global 
$smcFunc;

function 
CopyMemberData()
{
    
$smcFunc['db_query'](''"
                INSERT INTO {db_prefix}member_data (real_name)
                VALUES (" 
$regOptions['realName'] . ")"
            
);
}
?>

Suki

Is CopyMemberData the function been called by the hook?  that hook pass two vars, &$regOptions and &$theme_vars

So your function must declare them as well:

<?php
if (!defined('SMF'))
die('Hacking attempt...');


function 
CopyMemberData(&$regOptions, &$theme_vars)
{
    global 
$smcFunc;

    
$smcFunc['db_query'](''"
                INSERT INTO {db_prefix}member_data (real_name)
                VALUES (" 
$regOptions['realName'] . ")"
            
);
}
?>


BTW $regOptions['realName'] should be $regOptions['real_name']

I don't really get why you need to get the value and insert it on another table or in the members table, in fact, you shouldn't do that, the SMF register process will do that for you.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Alanar

I'm actually going to change it to member_name in the future, but it's because I am joining data from two tables in a query. That requires a common column, doesn't it?

Also, thanks for the declarations. I knew I was missing something!

The $regOptions['realName'] thing I got somewhere else as I thought it was strange they were declared differently there. Thanks again.

I'll check and make sure this all works tonight.

And I didn't mean I was inserting the real_name variable into the members table, I just meant I also wanted it in the second table.

Alanar

So now the query is giving me a hacking attempt error from the register2 function. Is there something else that I'm missing? I even tried including SSI.php to no avail.  :(

Alanar

Fixed by setting $modSettings['disableQueryCheck'] = true; and then re-enabling it afterwards. Thanks again for the help!

Advertisement: