tags:

views:

1388

answers:

6

I cannot seem to get a message from drupal_set_message when a user registers on my site. I'm using Drupal 6.14.

Adding a print in the user.module:

function user_register_submit($form, &$form_state) {
  ...
      if ($notify) {
        ...
      }
      else {
        drupal_set_message(t('Your password and further instructions have been sent to your e-mail address.'));
        print 'xxxxxx';
        $form_state['redirect'] = '';
        return;
      }
    }
    ...

}

It prints 'xxxxx';

A var_dump of the $_SESSION variable gives the status message, which drupal_set_message doesnt display, so that looks fine also.

I've uninstalled all my modules, only core remains, and using Garland now as a theme.

Furthermore, I've installed a fresh Drupal installation, and there it gives me a nice status message.

Then i compared my .htaccess and Drupal's, from the fresh install. Modified mine to make them equal.

Nothing helps.

Any thoughts?

A: 

I am facing the exact same problem too. I am running Drupal 6.10. I would appreciate any pointers on this. Thanks.

SRP
+4  A: 

We just solved it. Apparently, user 0 was missing, somebody deleted it or some module did it. After inserting it into the database we got our messages again.

This is what you have to do:

INSERT INTO `users` (`uid`, `name`, `pass`, `mail`, `mode`, `sort`, `threshold`, `theme`, `signature`, `signature_format`, `created`, `access`, `login`, `status`, `timezone`, `language`, `picture`, `init`, `data`) VALUES
(0, '', '', '', 0, 0, 0, '', '', 0, 0, 0, 0, 0, NULL, '', '', '', NULL);

And after that set the uid to 0, because uid is an autoincrement!!

No idea still how that messus up with drupal_set_message, though.

Dr. Hfuhruhurr
Thank You, thank you, thank you - I have been struggling all days long to find a solution. I would never picked it up. Just forgotten long time ago I deleted record 0 from users by some strange reason. Bless you.
Lukasz
A: 

Another problem could be that your theme doesn't print $message in the templates.

googletorp
No, as mentioned in the original post, we first switched to garland to rule that out. After that we removed module after module. We solved it by adding missing user 0.
Dr. Hfuhruhurr
It's still a possibility, either if you changed in the theme or deleted it by accidence. Also posted it more as a response to the 2nd guy or whoever else may come in the future, since the most comment problem, it that $message is deleted from the template. Another thing is that when you delete the anonymous user (uid 0), that only effect messages displayed to users that are not logged in, since the messages are saved in the session. So it would still work for users that are logged in.
googletorp
$message"s", I think.
Sepehr Lajevardi
+5  A: 

Hi, nicely done finding the cause - I had this exact same problem a couple of weeks or so ago.

Now, for the reason:

Drupal sessions are linked by ID number (you can see this in the session table in the database if you look) to the user. Drupal also has it's own session handling functions, and one of those is a check to see if the current session is associated with a valid user account - and for anonymous users, that is the user 0 - (it doesn't matter if multiple sessions are open per user - which is certainly what happens when so many anonymous users visit your site).

If Drupal does not find a valid user for the current session, then the session is regenerated anew - meaning the previous information is lost.

Edit:

A recent comment has prompted me to add a bit more depth to the answer as I have since found the most likely cause for the error.

Basically, it's the use of ID 0 for the anonymous user. If you INSERT a 0 value into an auto-incrementing field in MySQL, the value will actually become the next available value in the sequence (so, a table with auto-incrementing field set to 10 will INSERT at 11 and not 0).

We hit the problem because we were using MySQL dumps for exporting and importing backups during development.

HorusKol
Thx! marked your answer as accepted :)
Dr. Hfuhruhurr
This hast cost me a lot of hours too. Thanks for putting it up here.
stefan
A: 

I couldn't get messages to show up even when doing theme_get_messages() or echo $messages etc.

So I had to get it from $_SESSION['messages'].

ie:

<?php 
            // we aren't getting messages, get them manually
            if (isset($_SESSION['messages'])) {
                echo '<div class="messages">';
                foreach($_SESSION['messages'] as $type=>$messages) {
                    echo "<p class=\"$type\">".implode("</p><p class=\"$type\">", $messages)."</p>";
                }
                echo '</div>';
                unset($_SESSION['messages']);
            }

        ?>

Hope that helps someone.

bucabay
A: 

Thanks..

its works....User 0 was deleted from users table... Thanks again.. Amit

amit

related questions