We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

PHP bug?

Development and Programming

mweichert's avatar
mweichert
68 posts
16 years ago
mweichert's avatar mweichert

Hello,

I was wondering I could get someone to look at a module function for me. Maybe I’ve just been trying to debug it for too long.

Here is the function:

/**
 * Retrieves the notification e-mail configured for a member
**/
public function notification_email($member_id=0)
{
  global $TMPL, $DB, $FNS, $LANG, $OUT;
       
  $LANG->fetch_language_file('email_template');
        
  $email = '';
        
  // Set member id
  if (!$member_id) {
    $member_id = $TMPL->fetch_param('member_id') ? $TMPL->fetch_param('member_id') : $TMPL->fetch_param('author_id');
  }
  
  // Validate - BUG STARTS HERE
  echo $member_id; // displays a 'true' value, e.g. 23
  if (!$member_id) return $OUT->show_user_error('general', array($LANG->line('invalid_member_id')));
            
  // Retrieve e-mail address
  $query = $DB->query("SELECT m_field_id FROM exp_member_fields WHERE m_field_name = 'email_template_notify_email'");
  $m_field_id = $query->row['m_field_id'];
  $query = $DB->query("SELECT m_field_id_{$m_field_id} FROM exp_member_data WHERE member_id = ".$DB->escape_str($member_id));
  if ($query->num_rows != 0) $email = $query->row['m_field_id_'.$m_field_id];
        
  // Determine whether to var swap the value in data data
  if ($TMPL AND $TMPL->tagdata and $email) {
    $vars = array('notification_email' => $email);
    return $FNS->prep_conditionals($FNS->var_swap($TMPL->tagdata, $vars), $vars);
  }
        
  return $email;
}

The echo statement outputs what I’d expect when a value is present, the id of the member (e.g. 23). For some reason, the following line ALWAYS gets executed:

return $OUT->show_user_error('general', array($LANG->line('invalid_member_id')));

If I remove that statement (and the surrounding if statement), member_id appears to be NULL or an empty string. I cannot for the life of me figure this out and I’m totally confused.

Any help would be much appreciated.

Thanks, Mike

       
mweichert's avatar
mweichert
68 posts
16 years ago
mweichert's avatar mweichert

Btw, the forgot to mention - the function takes a parameter ‘member_id’ because I call this method from another module function internally.

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
16 years ago
Pascal Kriete's avatar Pascal Kriete

It’s probably something silly, but I can’t see the bug either. Could you try var_dump’ing the variable to see what it’s being set as:

// Validate - BUG STARTS HERE
// echo $member_id; // displays a 'true' value, e.g. 23
// if (!$member_id) return $OUT->show_user_error('general', array($LANG->line('invalid_member_id')));
if( ! $member_id)
{
    var_dump($member_id);
}

Also, how are you calling the function?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.