I tracked the problem after looking more into the punbb code.

Since I'm using another database class alongside the punbb one, I had to declare another global variable ($mydbvar) in the message function.

function message($message, $no_back_link = false)
{
    global $mydbvar, $db, $lang_common, $pun_config, $pun_start, $tpl_main;

Thank you for your patience and help.

OK thanks - I'll try get more specific info.

Perhaps the message function does not do a redirect but that is the outcome if the true parameter is added.

From the profile page when you edit your password and enter non-matching passwords this is called...
message($lang_prof_reg['Pass not match']);
Which displays the error message.

If you enter matching passwords and it changes the password successfully it calls this
message($lang_profile['Pass updated'], true);
Which does whatever it does then takes you to the redirect page saying "Pass updated" then directs you back to your profile page.

Put simply, my code (that one line of call that does a database call) works fine when the password matches, but does not when there is a password mismatch (or any other message).

I'll  try and gather more info or files to make it easy for you to replicate.

OK I've been testing by commenting out everything in my user template files and here is what I have come up with...

If I have this code in any of my user template files, it breaks and does not display the full template file:

$results_nav = $mycustomdbclass_db->GetAll("SELECT blah FROM blah WHERE blah ORDER BY disp_order ASC");

BUT, only when this function is called do I have a problem:

message($lang_prof_reg['Pass not match']);

WHEN this function is called it is OK (and does the redirect I was talking about):

message($lang_profile['Pass updated'], true);

Is my line of code out of scope somehow when the message function is called without the true parameter?

P.s. Yes "$mycustomdbclass_db" is intentional - I am using my own DB class for these calls, which works everywhere on punbb except with the message function as shown above.

I think I've pin-pointed this scenario where I have problems - hopefully I can explain it.

If I use user templates in my main.tpl such as this:
<pun_include "mybody.php">

and mybody.php has includes like this:

<?php include SITE_ROOT."includes/mainbody.php"; ?>

Then whenever the message function in functions.php is run it does not correctly load the header correctly:
i.e. this line

if (!defined('PUN_HEADER'))
    {
        global $pun_user;
        $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Info'];
        require PUN_ROOT.'header.php';
        // THE LINE ABOVE IS NOT LOADING THE HEADER CORRECTLY IN HEADER.PHP WHEN I HAVE THE TEMPLATE STRUCTURE ABOVE. WHEN I MAKE THE USER INCLUDES NOT HAVE INCLUDES IN THEMSELVES IT WORKS FINE
    }

Let me also add that this error only occurs when the message function is sent without a TRUE parameter (when it does not trigger a redirect). An example of the user behavior is to change your password and enter a mismatched password which triggers the message function without the redirect.

Steven I never received your email. I also sent you an email via the email address listed in your profile - let me know if you did/didn't get it.

I'm looking for someone who would be interested in a paid job to create a plugin to import my forum data from my current forum into PunBB.  My current forum is a custom forum but it should contain all the data needed to do the transfer (but the table structure and number of tables in the two forums is quite different).

Any takers - quite happy to pay someone $$$.