db_query() doesn't seem to run in module I have a custom user-management module in my Drupal 6 site. We are a corporate subscription service and needed a way for a subscribing company's primary user to delete other users from their company. When this happens, we need to not only delete the Drupal user record for that person, but also make some changes to a record in another mySQL database that's connected to one of our internal non-Drupal systems. There's a lot of jquery stuff involved, but the main thing is that a user clicks a delete link next to a name in a list of users. The link looks like this:

http://mysite.com/account/manage/disappear/1/182741


The final three params are what we use - disappear is the action (there are also promote and demote, which allow the primary user to change the type of account other users have), 1 is the Drupal ID of the primary user (in this case, I'm logged in as user 1), and the final param is the ID from our non-Drupal database. From that ID's record, we can find the Drupal account ID we need to delete (as well as other info we need for this function that are not specifically Drupal-related.)

Most of it works correctly - the user is deleted and the email is sent, but the query that's supposed to update our other database doesn't seem to be running. Can anyone help me out? Is there a way to debug queries? I know I'm dealing with the correct records; the error_log line right inside the disappear case returns the correct values.

Here's the function (I've stripped out the promote and drop actions since they work. Also, Viola is our intranet app where the non-Drupal database lives)

function user_manage_function($action, $uid, $viola, $email_prefix = '', $email_domain = '') {

    // action = delete, promote or drop?
    // uid = the UID of the primary user, as a security measure
    // viola = the Viola people ID of the person we want to promote, delete or drop
    // email fields = if the PU adds an email address, we need to verify it

    global $user;

    if ($user-&gt;uid == $uid) { # just a sanity check to make sure we know the current primary user

        // see what their UID is ... set $vuid = the drupal uid of the promoted/dropped/deleted user
        $people_row = db_fetch_object(db_query("SELECT institute_uid, email FROM {ismi.new_people} WHERE id = %d", $viola));
        $vuid = $people_row-&gt;institute_uid;
        $viola_email = $people_row-&gt;email;
        $data = 'pending';

        if ($vuid) {

            switch ($action) {

            case "disappear":
                error_log("inside main disappear - vuid=$vuid and viola=$viola");
                  $quer = db_query("UPDATE {ismi.new_people} SET active = 0, insitute_uid = 0 WHERE id = %d", $viola);
                    user_delete(array(), $vuid);
                    $message = array(
                        'to'                =&gt;  'test@test.com',
                        'subject'       =&gt;  t('User deleted by primary user'),
                        'body'          =&gt;  t($user-&gt;name . ' (' .$user-&gt;mail.') just deleted the Institute website account for '. $viola_email),
                        'headers'       =&gt;  array('From'=&gt;'test@test.com'),
                    );
                    drupal_mail_send($message);
                    break;
            }

            $data = 'success';
    }
  }
}
You write that


  but also make some changes to a record in another mySQL database that's connected to one of our internal non-Drupal systems


so I figure that you need to query a different MySQL database, but in your don't change the active database using db_set_active. This is most likely the root to your problem.

If the SELECT query works, then the code you have provided should work just fine.

A simple way to test your problem, would be run db_query on a known record and see if you can alter it. Devel also offers query logging, which would allow you to log the actual UPDATE and alternatively try to run the raw query through a MySQL interface.

Another explanation could be that you have the ismi.new_people table in the Drupal db, so you in fact are updating the wrong table/database.

Another possible problem is database  permissions. Do your DB user have read only access?