I am very new to Drupal.

  • I have a table called test with two fields: (int) id and (varchar) text
  • When a new user signs up I want to store data on the table test

I'd like to know how can I do that. I really don't know how to start researching about this.

I think the most approximately that I have found is Overriding user login. I presume that it does what I want but in the pre-process functions I have to insert into the database. Question here how do I insert into the database from Drupal?

Could anyone clear my thoughts or point me to any good reference.


1 Answer 1


You don't need to actually override the login process to do this; The user module provides a hook (hook_user_insert()) which gets invoked any time a new user is created.

As far as inserting into the database goes, the best place to look first is the Database abstraction layer documentation which goes into detail about the various database methods available.

In this specific case it's the db_insert() function you're looking for. Your code might look something like this:

function MYMODULE_user_insert(&$edit, $account, $category) {
      'id' => $account->uid,
      'text' => 'some text'

This code would go inside a custom module; if you're not familiar with creating one of those check out the Module developer's guide which will tell you everything you need to know.

  • Many thanks man, but actually I need to do it in the registration. Is there any hook for the registration? and in which file should I put this code? Commented Jul 6, 2012 at 10:52
  • My bad I didn't read the question properly ;) I'll update the answer
    – Clive
    Commented Jul 6, 2012 at 10:53
  • There, that should make more sense
    – Clive
    Commented Jul 6, 2012 at 10:59

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.