Reputation: 1
I need to run a SQL command right after a new user account has been created (I need to obtain new User ID also). (in Drupal 7)
How can I do this?
Upvotes: 0
Views: 48
Reputation: 27023
Build a custom module with hook_user_insert implementation.
Here's a code sample that saves the new user's id into a table called test_table
.
function [YOUR_MODULE]_user_insert(&$edit, $account, $category) {
$newUserId = $account->uid;
db_insert('test_table')
->fields(array(
'user_id' => $newUserId,
))
->execute();
}
Upvotes: 0
Reputation: 1148
In a custom drupal module, use hook_user_insert.
within that function the $account variable with have the new user data and user id number.
To run custom sql query, you can use drupal's db_query function.
If you need to learn about custom drupal module development, take a look at the example modules.
Upvotes: 1