0

I am registering users via csv file. I get user details, then save them in the usual users table using the JUser class. What is not working are extra columns I have. I've created them in the db already. My code is as below

$pass = 'xxxxxxx'; //default
$data = array(
    "name"=>$allnew[$i]->name,
    "username"=>$allnew[$i]->username,
    "password"=>$pass,
    "password2"=>$pass,
    "email"=>$allnew[$i]->email,
    "telephone"=>$allnew[$i]->telephone,
    "test"=>strtolower($allnew[$i]->test),
    "test1"=>$allnew[$i]->test1,
    "gid"=>18,
    "usertype"=>$newUsertype
);
$userr = new JUser;

if(!$userr->bind($data)) {
    throw new Exception("Could not bind data. Error: " . $userr->getError());
}

$userr->set('id', 0);
$userr->set('usertype', $newUsertype);
$userr->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));
$date =& JFactory::getDate();
$userr->set('registerDate', $date->toMySQL());
$userr->set('leavedays', $data['leavedays']);
$useractivation = $usersConfig->get( 'useractivation' );

if ($useractivation == '1')
{
    jimport('joomla.user.helper');
    $userr->set('activation',$pass );
    $userr->set('block', '1');
}

if($userr->save()) {
    echo ' Success';
} else { echo 'error'; }

Please help. test and test1 are not being saved and I can't tell why. Both columns exist in the database.

5
  • 1
    In 2015 why are you still using Joomla 1.5? Using an outdated, unmaintained, and potentially vulnerable version of the CMS is not a good idea. You should also avoid modifying the core, you should look at user profile plugins. You would be able to save your additional data in a separate table, be able to set up your CSV registration, and provide users the ability to see (and possibly edit) their information Commented Dec 5, 2015 at 13:24
  • because a client gave us a job. A client who wants that j1.5. Not I as a developer. So, I've to work with what he wants man Commented Dec 7, 2015 at 5:38
  • Those kinds of jobs are the worst, in the next 3-6 months; if they get hacked they will likely blame you for making their vulnerable site vulnerable. In any case, plugins are the right way to approach this project, not hacking the core. Commented Dec 8, 2015 at 3:31
  • Actually, I already hacked. Hacking it is safest. You want to trust a plugin for that? Understand the core, make a copy, add your functionality. Plus, this version, even the plugins availability is another factor. Commented Dec 8, 2015 at 5:01
  • 1
    Hacking the core is never the safest. Learn about plugins, Plugins will give you the ability to extend the core functionality. If something was discovered and patched in J1.5 a "hacked" core would block implementing the patch. Whereas if you created a plugin you would be safe to implement the patch without losing your customization. Commented Dec 9, 2015 at 6:34

1 Answer 1

1

I assume the values for the default columns are being saved.

I believe the function to add the users in the database only defines the default columns, therefore even if you add your own columns to the #__users table, they still won't be defined.

Rather than changing the #__users table, I'd suggest creating a new table with with following columns:

  • id
  • uid (This is the ID of the user)
  • test
  • test1

When you add a new user using JUser, write a database query which will add the addition values into your newly created table.

5
  • how do i make the jos_users table accept custom columns/fields? Commented Dec 2, 2015 at 9:50
  • Would either require a core hack (not recommended), or creating a custom plugin that extends the JUsers class
    – Lodder
    Commented Dec 2, 2015 at 9:58
  • I would love that core hack. how do i go about it? Commented Dec 2, 2015 at 10:12
  • 1
    Sorry, I never recommend core hacks. If someone else would like to, they can
    – Lodder
    Commented Dec 2, 2015 at 10:28
  • "how do i make the jos_users table accept custom columns/fields?" I wouldn't. The problem with j1.5 is that it is insecure and regularly targeted for vulnerabilities - it's just a matter of time before it is hacked. After the first couple of J1.5 clients who were reluctant (ie. too cheap) to update their site, got hacked, it cost them and me more than it was worth. So I strongly convinced my other clients to update.
    – garth
    Commented Dec 9, 2015 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.