Customizing SMF > SMF Coding Discussion

Register a user from a small PHP file hidden somewhere.

<< < (3/5) > >>

madturnip:
I get an error on this line of code:


--- Code: --- groups[$row['id_group']] = $row['group_name'];
--- End code ---

Below is the test.php file, but line 11 throws an error.  When I place $ in front of groups it then errors out on line 7 with this message:

Fatal error: Function name must be a string in /home/mcrider/public_html/test.php on line 7

test.php


--- Code: ---<?php

function loadLogic() {
    
    global $smcFunc, $sourcedir, $groups;

    $request = $smcFunc['db_query'](
        'SELECT id_group, group_name
        FROM {db_prefix}membergroups');
    while ($row = $smcFunc['fetch_assoc']($request))
        groups[$row['id_group']] = $row['group_name'];
    
    // Only do this part if the submit button was pressed
    if (isset($_POST['submit'])) {
        // Make sure we include the registration function
        require_once($sourcedir . '/Subs-Members.php');
        
        // Sanitize some data
        $username = !empty($_POST['user']) ? 
            $smcFunc['htmlspecialchars']($_POST['user'], ENT_QUOTES) : '';
        $email = !empty($_POST['email']) ? 
            $smcFunc['htmlspecialchars']($_POST['email'], ENT_QUOTES) : '';
        $password = !empty($_POST['passwrd']) ? 
            $smcFunc['htmlspecialchars']($_POST['passwrd'], ENT_QUOTES) : '';
        
     $regOptions = array(
     'interface' => 'admin',
     'username' => $username,
     'email' => $email,
     'password' => $password,
     'password_check' => $password,
     'openid' => '',
     'auth_method' => '',
     'check_reserved_name' => true,
     'check_password_strength' => false,
     'check_email_ban' => false,
     'send_welcome_email' => !empty($modSettings['send_welcomeEmail']),
     'require' => 'nothing',
     'extra_register_vars' => array(),
     'theme_vars' => array(),
            'memberGroup' => !empty($_POST['group']) && is_numeric($_POST['group']) ?
                $_POST['group'] : -1,
     );
    
        registerMember($regOptions);
    }
}

$groups = array();
loadLogic();

echo '<form action="" method="post">
    <input type="text" name="username" />
    <input type="password" name="passwrd" />
    <input type="text" name="email" />
    <select name="group">';
    
    foreach ($groups as $key => $value)
        echo '<option value="' . $key . '">' . $value . '</option>';
        
echo '</select>
    <input type="submit" name="submit" value="Submit" />
 </form>';
?>
--- End code ---

Anthony`:

--- Quote from: madturnip on March 11, 2012, 04:54:48 PM ---I get an error on this line of code:


--- Code: --- groups[$row['id_group']] = $row['group_name'];
--- End code ---

--- End quote ---

Forgot my $. Try the code again.

madturnip:
refer to Reply 10 above...   I did that and it errors out:

Fatal error: Function name must be a string in /home/mcrider/public_html/test.php on line 7

I am sorry man! I am a total noob if I am doing something wrong.  I just added the <?php and ?> to the file and expected it to work.  Maybe it was suppose to have other code with it.  Again, I apologize for being very unskilled when it comes to PHP programing.

Anthony`:

--- Quote from: madturnip on March 11, 2012, 05:05:55 PM ---refer to post before this one...   I did that and it errors out:

Fatal error: Function name must be a string in /home/mcrider/public_html/test.php on line 7

--- End quote ---

Right right, I forgot to include SSI.php for the actual script. Updated.

madturnip:
Ok it got passed the error....    Now, however, it give the following error:


--- Quote ---Warning: Missing argument 2 for smf_db_query(), called in /home/mcrider/public_html/forum/test.php on line 14 and defined in /home/mcrider/public_html/forum/Sources/Subs-Db-mysql.php on line 221
Database Error
Query was empty
File: /home/mcrider/public_html/forum/test.php
Line: 14
Back
--- End quote ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version