0

Good afternoon all. I would like to implement a custom query during the registration process of my registration. I've taken a look around online and can't find the information anywhere, so if anybody knows where the registration query is ran, so that I can add another query to it that would be awesome. Thanks in advance. EDIT The Query that runs alongside will go into a seperate game database, so alongside of the standard query it will also run This was my old query, so maybe it can help show what I'm trying to run.

  $server= "****";
    $user= "****";
    $pass= "****";
    $gamedb= "****";

$link = mysqli_connect("$server", "$user", "$pass", "$webdb") or die( "Error:" . mysqli_connect_error());
$username = mysqli_real_escape_string($link, (string) $_POST['username']);
$email = mysqli_real_escape_string($link, (string) $_POST['email']);
$password = sha1((string) $_POST['password']);
$query="INSERT INTO user (`username`, `email`, `password`, `permissions`)
VALUES ('$username', '$email', '$password', '1')";
mysqli_query($link, $query) or die ("Error:" . mysqli_errno($link));
mysqli_close($link);
1
  • Can you elaborate a bit on what you are trying to accomplish with the additional query? There are a few ways to tackle this, but we need more information to help you out.
    – mpdonadio
    Nov 19, 2012 at 22:50

1 Answer 1

0

The use of the hook_user_insert() it is call when the user is created. Here is an implementation example:

    function hook_user_insert(&$edit, $account, $category) {
      db_insert('mytable')
        ->fields(array(
        'myfield' => $edit['myfield'], 
        'uid' => $account->uid,
      ))
        ->execute();
    }

Depending on your case you might want to check other hooks like:

hook_user_insert()

hook_user_presave()

hook_user_update()

2
  • I'll see if I can't find this somewhere within haha. I've always just created my sites by scratch but I decided to cave in and start looking into drupal development. Nov 19, 2012 at 22:12
  • The concept behind drupal is not to hack the core or the files you downloaded from drupal.org instead you will use hooks that are functions that will enhance the functionality that already exist. To use the code I posted you will create your own small custom module and in the function you will replace the word "hook" in the function for your module name. Here you will find how to create a module: drupal.org/node/361112
    – Emil Orol
    Nov 19, 2012 at 22:17

Your Answer

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

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