Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8645755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:37:52+00:00 2026-06-12T12:37:52+00:00

i am trying to insert another info to joomla (2.5.7) database after user is

  • 0

i am trying to insert another info to joomla (2.5.7) database after user is registered. The user chooses his usergroup and I want the insertion to happen only when the user is in a specific group. So I am trying to use this code to get the group data from the databse first to be used in the insert query. Now it is just a testing ground, later this retrieved value be used in if statement.

This is the code:

function onUserAfterSave($user, $isnew, $success, $msg)
    {
    if ($isnew && $success) {
  $db = &JFactory::getDBO();
  $query = "SELECT #__k2_users.group FROM #__k2_users WHERE userID = ".$user['id'];
  $db->setQuery($query);
  $group = $db->loadResult();

  $db->setQuery( 'INSERT INTO #__user_profiles (ordering) VALUES ('.$group.')' );
  $db->query();
   if (!$db->query()) 
   {
    throw new Exception($db->getErrorMsg());
   }  
  }
    return $this->onAfterStoreUser($user, $isnew, $success, $msg);
}

and this is the error I am getting upon the failed registration:

Column count doesn't match value count at row 1 SQL=INSERT INTO std13_user_profiles (ordering) VALUES ()

If I read it correctly, it means that the select statement is not returning anything but why? Thank you for your help.

UPDATE:

 if ($isnew && $success) {
  $db = &JFactory::getDBO();
  $userId   = JArrayHelper::getValue($user, 'id', 0, 'int');
  $query = "SELECT #__k2_users.group FROM #__k2_users WHERE userID = ".$userId;
  $db->setQuery($query);
  $group = $db->loadResult();


    $query2 = "INSERT INTO #__user_profiles (ordering) VALUES ('".$group."')";
    $db->setQuery($query2);
    $db->query();
   if (!$db->query()) 
   {
    throw new Exception($db->getErrorMsg());
   }  
  }

with this code, I don’t get any errors and the user is registered and the values are inserted. However the $group is always 0 and based on the value is only 1 or 3 in k2_users table, I am guessing that it returns nothing. I think it may be because the registered user is not stored in the databse yet and it doesn’t have his ID yet to look for the group?

UPDATE2:

if ($isnew && $success) {

    $count = JRequest::getVar('gender');
    if($count == 3) {

    $db = &JFactory::getDBO();
    $alias = $user['name'];
    $table = array(
    ' '=>'-', 'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj', 'Ž'=>'Z', 'ž'=>'z', 'C'=>'C', 'c'=>'c', 'C'=>'C', 'c'=>'c',
    'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
    'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O',
    'Õ'=>'O', 'Ö'=>'O', 'ě'=>'e', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss',
    'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e',
    'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o',
    'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b',
    'ÿ'=>'y', 'R'=>'R', 'r'=>'r', " "=>'-', '"'=>'-'
);
    $string = strtr($alias, $table);
    $alias_low = strtolower($string);
    $query = "INSERT INTO #__menu (menutype, title, alias,  path, link, type, published, level, component_id, access) VALUES ('stavebnici','".$user['name']."','".$alias_low."','".$alias_low."',
    'index.php?option=com_k2&view=itemlist&layout=user&id=".$user['id']."&task=user','component',1,1,10012,1)";
    $db->setQuery($query);
    $db->query();
   if (!$db->query()) 
   {
    throw new Exception($db->getErrorMsg());
   }
   }  
  }

OKAY! I got it working so now I can insert new menu every time a user is created, however th activation link is not created and the registration says that it failed. This is the error:

Duplicate entry '0-1-vojtech-plesner-' for key 'idx_client_id_parent_id_alias_language' SQL=INSERT INTO std13_menu (menutype, title, alias, path, link, type, published, level, component_id, access) VALUES ('stavebnici','Vojtěch Plešner','vojtech-plesner','vojtech-plesner', 'index.php?option=com_k2&view=itemlist&layout=user&id=2789&task=user','component',1,1,10012,1)

The client_id, parent_id and language have values of 1,1 and * abd they are in all the rows so why is it saying it is duplicate?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:37:53+00:00Added an answer on June 12, 2026 at 12:37 pm

    You need to update that query to 2.5 style.

    http://www.theartofjoomla.com/home/9-developer/135-database-upgrades-in-joomla-16.html

    is a good article.

    You definitely seem to be missing
    $query = $db->getQuery(true);

    not to mention that you are using & for an object. That usage will generate strict errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Description: I am trying to insert user's preferences into a database. If the user
I'm trying to insert another table row into a table after calling from a
I am trying to insert a user id from devise into another table which
I am trying to insert a div inside another div using add() of jquery
I'm trying to insert the contents of one map to another. Here is the
I am trying to select data from two tables and insert it into another
Trying to insert 315K Gif files into an Oracle 10g database. Everytime I get
I'm trying to insert the current date/time to the database as the last time
I am trying to insert a block element Insert something before another . I
I am trying to insert data from one table to another with same structure,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.