What is wrong with this plugin code?  Variable not being read in SQL query
Posted: 16 December 2008 02:49 AM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  361
Joined  06-24-2007

This code works fine as shown, echoing the $member_id value to the screen, and then running the following query.  Notice, though, that the member_id in the SQL statement is hard coded as 1. 

When I change the SQL to say member_id = ‘$member_id’ , which is how I want it to work, the query returns no rows and the die statement is executed.

However, as I said, I know the $member_id variable is valid because it is printing correctly to the screen (member 64, in my test case). 
And I know the SQL statement works just fine when hard coded with 1 in it.

Ideas?

global $TMPL$DB$REGX;

        
$member_id        $TMPL->fetch_param('member');
        
$name            $TMPL->fetch_param('name');
        
$type            $TMPL->fetch_param('type');
        
        if (!
$member_id{
            
die('no member_id');
        
}
        
        
if (!$name{
            
die('no name');
        
}

        $this
->return_data .= $member_id;
        
        
//Get the user's information from the members table
        
$query $DB->query("Select username, screen_name, email from exp_members where member_id = '1'");
                
                if (
$query->num_rows == 0{
                    
                    
//does this member_id exist?  This is weird...
                    
die('no member ID');
                    
                
else {
                    
                    $username 
$query->row['username'];
                    
$screen_name $query->row['screen_name'];
                    
$email $query->row['email'];
                    
                
 Signature 

Chad Crowell | Encaffeinated, Inc. | @chadcrowell | @encaffeinated

Profile
 
 
Posted: 16 December 2008 05:29 AM   [ Ignore ]   [ # 1 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  13771
Joined  04-15-2006

Hi Chad,

I don’t know what your plugin tag code looks like as I can’t see what it is called but are you definitely making sure to do this :

{exp:your_plugin_name member="{member_id}"}
<p>Answer here…</p>
{/exp:your_plugin_name} 

instead of possibly :

{exp:your_plugin_name member_id="{member_id}"}
<p>Answer here…</p>
{/exp:your_plugin_name} 

I just ask as I noticed that you have name and type in your parameters but then you have placed in your code member instead of member_id. Just wondering if you were possibly placing the parameter in the plugin code as member_id perhaps and then the plugin is expecting a parameter called member?

Just a thought though.

The other question would be how are you sending the member / member_id to the plugin? In other words how is the plugin getting hold of the number? Is this plugin placed within a weblog tag or something else?

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors

Profile
 
 
Posted: 16 December 2008 12:38 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  361
Joined  06-24-2007

Hi Mark-

Here is the call:

{exp:member_update_notification member="{member_id}" name="{screen_name}" type="{segment_3}"

As I said, the $member_id variable IS getting the data correctly, because the $this->return_data code does print the correct member_id to the web page. 

Below is the whole plugin.  I changed the die code to be more accurate, but it still fails there at the first SQL command.  I also updated the SQL command to show you how it should look.

<?php

/*
=====================================================
 File: pi.member_update_notification.php
-----------------------------------------------------
 Purpose: Send email to church office on update of user account
=====================================================

*/


$plugin_info = array(
                        
'pi_name'            => 'Member Update Notification',
                        
'pi_version'        => '1.0',
                        
'pi_author'            => 'Chad Crowell',
                        
'pi_author_url'        => 'http://webinception.com/',
                        
'pi_description'    => 'Send email to church office on update of user account',
                        
'pi_usage'            => Member_update_notification::usage()
                    );


class 
Member_update_notification {

    
var $return_data;

    
    
/** ----------------------------------------
    /**  Do it
    /** ----------------------------------------*/

    
function Member_update_notification()
    
{
        
global $TMPL$DB$REGX;

        
$member_id        $TMPL->fetch_param('member');
        
$name            $TMPL->fetch_param('name');
        
$type            $TMPL->fetch_param('type');
        
        if (!
$member_id{
            
die('no member_id');
        
}
        
        
if (!$name{
            
die('no name');
        
}

        
//$this->return_data .= $member_id;
        
        //Get the user's information from the members table
        
$query $DB->query("Select username, screen_name, email from exp_members where member_id = '$member_id'");
                
                if (
$query->num_rows == 0{
                    
                    
//does this member_id exist?  This is weird...
                    
die('SQL query did not work...');
                    
                
else {
                    
                    $username 
$query->row['username'];
                    
$screen_name $query->row['screen_name'];
                    
$email $query->row['email'];
                    
                
}
        
        
        
//Get the entry_id for the member's profle, if it exists
        
$query $DB->query("Select entry_id from exp_weblog_titles where author_id = '$member_id' AND weblog_id = '9'");
                
                if (
$query->num_rows == 0{
                    
                    
//this member doesn't have a member profile
                    
$profile 0;
                    
                
else {
                    
                    $profile 
1;
                    
$profile_id $query->row['entry_id'];
                    
                
 Signature 

Chad Crowell | Encaffeinated, Inc. | @chadcrowell | @encaffeinated

Profile
 
 
Posted: 16 December 2008 12:38 PM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  361
Joined  06-24-2007
//Start our email content
        
$email_msg "Website member $screen_name has recently updated his/her profile. Below is their  profile information, which you can compare with what you currently have on record to find changes.\n\n";
        
$email_msg .= "Name: $screen_name\n";
        
$email_msg .= "Email: $email\n";
        
$email_msg .= "\n";
                

            
        
//if there is a profile that was updated, get the data within it
        
if ($profile == 1{
        
            $query 
$DB->query("Select field_id_45, field_id_46, field_id_47, field_id_48, field_id_49, field_id_50, field_id_51, field_id_52, field_id_53, field_id_54, field_id_55 from exp_weblog_data where entry_id = '$profile_id'");
                
                    if (
$query->num_rows == 0{
                    
                        
//that would be really weird...
                    
                    
else {
                    
                        $first 
$query->row['field_id_45'];
                        
$last $query->row['field_id_46'];
                        
$add1 $query->row['field_id_47'];
                        
$add2 $query->row['field_id_48'];
                        
$city $query->row['field_id_49'];
                        
$state $query->row['field_id_50'];
                        
$zipcode $query->row['field_id_51'];
                        
$phone $query->row['field_id_52'];
                        
$phone2 $query->row['field_id_53'];
                        
$bd_month $query->row['field_id_54'];
                        
$bd_date $query->row['field_id_55'];
                    
                    
}
                    
            
//Amend more info to the email
            
$email_msg .= "Address:\n";
            
$email_msg .= "$add1\n";
            if (
$add2{
                $email_msg 
.= "$add2\n";
            
}
            $email_msg 
.= "$city$state$zipcode\n";
            
$email_msg .= "\n";
            
            if (
$phone{
                $email_msg 
.= "Phone Number(s):\n";
                
$email_msg .= "$phone\n";
            
}
            
if ($phone2{
                $email_msg 
.= "$phone2\n";
            
}
            $email_msg 
.= "\n";
            
            if (
$bd_month != "Month" && $bd_date != "Date"{
                $email_msg 
.= "Birthday: $bd_month $bd_date\n";
            
}
                    
        }
        
        
        $email_msg 
.= "\nThank You!";
        
        
        
//Construct an email and send it to the church office
        
if ( ! class_exists('EEmail'))
        
{
            
require PATH_CORE.'core.email'.EXT;
        
}
        
        
        

        $email 
= new EEmail;
        
$email->wordwrap true;
        
$email->mailtype 'text';    
        
$email->from('donotreply@mydomain.org');
        
$email->to('changes@mydomain.org');
        
$email->bcc('chad@mydomain.com');
        
$email->subject('Member contact information update notification');
        
$email->message($REGX->entities_to_ascii($email_msg));
        
$email->Send();
        
        


    
}
    
/* END */
    
// ----------------------------------------
//  Plugin Usage
// ----------------------------------------

// This function describes how the plugin is used.
//  Make sure and use output buffering

function usage()
{
ob_start
(); 
?>

Ask Obi Wan
he will tell you how this works.

<?php
$buffer 
ob_get_contents();
    
ob_end_clean(); 

return 
$buffer;
}
/* END */



}
// END CLASS
?> 
 Signature 

Chad Crowell | Encaffeinated, Inc. | @chadcrowell | @encaffeinated

Profile
 
 
Posted: 16 December 2008 05:09 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  361
Joined  06-24-2007

Ah dumb me- should have been using the session class the whole time… fixed.

 Signature 

Chad Crowell | Encaffeinated, Inc. | @chadcrowell | @encaffeinated

Profile
 
 
Posted: 17 December 2008 06:33 AM   [ Ignore ]   [ # 5 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  13771
Joined  04-15-2006

Hi Chad,

Sorry I hadn’t been able to reply to this as I have come down with severe flu and stuck in bed as I write this. downer

Glad you have it sorted now though.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors

Profile