ListMailPRO Email Marketing Software Forums

ListMailPRO Email Marketing Software Forums => Customization, Integration => Topic started by: DW on June 25, 2004, 08:44:50 am

Title: Custom MySQL Insert Script - Perl
Post by: DW on June 25, 2004, 08:44:50 am
This script is for v1.77 to v1.84, the user database may change in future versions and the script will need to be updated.

Copy and paste the following code into a file named LMinsert.pl

Please read the notes near the top of the file for information about usage.

Code: [Select]
#!/usr/bin/perl
#
# v1.77 lm_users MySQL Table Format
#
# id  mediumint(9) - auto incrementing id
# uid  varchar(7) - unique user id, must be generated
# list  smallint(5) - list user belongs to
# fname  tinytext - first name
# lname  tinytext - last name
# email  tinytext - email address
# user1-user10 text - custom fields 1 thru 10
# cseq  smallint(6) - user's current seq # (next followup)
# cdel  smallint(6) - days to delay to next followup (0 is next dailymail)
# cnf  char(1) - 0=unconfirmed 1=confirmed 2=removed 3=bounced
# dateadd  date - YYYY-MM-DD date
# ipaddr  varchar(15) - ip address
# refurl  varchar(75) - referring URL
# htmail  char(1) - 1=HTML+Text 2=Just Text
# bounces  tinytext - dont mess with this one :/
#
#

# ListMail Insert User Function
#
# The first 2 parameters are required: list and email
# The rest are optional and their defaults specified: first name,last name, 10 custom fields, current seq #, current delay #, ip address, referring URL.
# The function will generate the UID and Date Added automatically

# example usage:
# require './LMinsert.pl';
# LMinsert('1','test@listmailpro.com','first','last','u1','u2','u3','u4','u5','u6','u7','u8','u9','u10','1','0','Unknown','Unknown');
# or
# LMinsert($list,$email);


# begin function

use DBI;

sub LMinsert {
if(!$_[0]){
print 'You must enter a list number';
return 0;
}
        if(!$_[1]){
                print 'You must enter an email address';
                return 0;
        }

$list = $_[0]; $em = $_[1]; $fn = $_[2]; $ln = $_[3]; $u1 = $_[4];
        $u2 = $_[5]; $u3 = $_[6]; $u4 = $_[7]; $u5 = $_[8]; $u6 = $_[9];
        $u7 = $_[10]; $u8 = $_[11]; $u9 = $_[12]; $u10 = $_[13]; $sq = $_[14];
$de = $_[15]; $ip = $_[16]; $ref = $_[17];

# default seq
if(!$sq){ $sq = '1'; }
# default delay
if(!$de){ $de = '0'; }
# default IP
if(!$ip){ $ip = 'Unknown'; }
# default ref url
if(!$ref){ $ref = 'Unknown'; }


# You -must- set the MySQL connection information below:

$sqlhost = 'localhost';
$sqldb = 'YOURDATABASE';
$sqluser = 'YOURUSERNAME';
$sqlpass = 'YOURPASSWORD';


# Additional Options for duplicate email addresses on the same list
# Unset or comment to disable

$allow_dupes = 1;
# $overwrite_dupes = 1;
# $ignore_dupes = 1;

# End config

# Begin script

# Connect to MySQL
$dbh = '';
$dbh = DBI->connect("DBI:mysql:$sqldb:$sqlhost",$sqluser,$sqlpass);

# check for duplicates
if(!$allow_dupes){
                $cmd = "select id from lm_users where list = '$li''and email like '$em'";
                $quer = $dbh->prepare($cmd);
                $quer->execute();
                $rows = $quer->rows;
#  duplicate found..
if($rows>0){
list($xid,$xcnf)=mysql_fetch_row($result);

# if they were removed or unconfirmed, remove them and reinsert
if($xcnf=='2' || $xcnf=='0'){
$dupe = '';
$cmd = "delete from $utable where id = '$xid'";
$quer = $dbh->prepare($cmd);
$quer->execute();
# otherwise check if we're overwriting dupes
} else {
if($overwrite_dupes){
$dupe = '';
                               $cmd = "delete from $utable where id = '$xid'";
                               $quer = $dbh->prepare($cmd);
                               $quer->execute();
# this is a duplicate that won't be allowed in
} else {
$dupe = 1;
}
}
}
# allowing dupes
} else {
$dupe = '';
}

if($dupe){ return 0; }

# make date Y-m-d

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

$mon += 1;
if($mon<10){ $mon = '0'.$mon; }
$year += 1900;
$da = "$year-$mon-$mday";

        # make id
        $done = '';
        while(!$done){
                my $xuid=lc(&calcstr(7));
                $cmd = "select id from lm_users where uid = '$xuid'";
                $quer = $dbh->prepare($cmd);
                $quer->execute();
                $rows = $quer->rows;
                if($rows==0){
                        $done = 1;
                        $uid = $xuid;
                        # print "UID $uid not found.. continuing";
                        $quer->finish()
                }
        }
$dbh->do('INSERT INTO lm_users VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',undef,('null',$uid,$list,"$fn","$ln","$em","$u1","$u2","$u3","$u4","$u5","$u6","$u7","$u8","$u9","$u10","$sq","$de",'1',$da,"$ip","$ref",'1','0'));


return 1;
}

sub calcstr {
        my $length_of_randomstring=shift;#the length of the random string to generate
        my @chars=('a'..'z','A'..'Z','0'..'9','_');
        my $random_string;
        foreach (1..$length_of_randomstring)
        {
                #rand @chars will generate a random number between 0 and scalar @chars
                $random_string.=$chars[rand @chars];
        }
        return $random_string;
}
return 1
Title: Custom MySQL Insert Script - Perl
Post by: gwill23 on August 31, 2004, 06:49:01 am
Here is my register.cgi with the modification I think you told me to make.  It didn't work.  Can you look at lines 9, 206, and 207 and see if I did them right.  I have them commented out but I can put them back in any time.

Quote
#!/usr/bin/perl

#(C) Gustavs Avotins, 2001

do 'sessions.cgi';
do "$Progcfg";
do 'sendemailfunc.cgi';
do 'delayedemails.cgi';
#require 'http://www.opportunityone.net/cgi-bin/LMinsert.pl';

$SiteURL=~/(.*\/\/[\w.-]*)[\/]?/;$RootURL=$1;

if ($ENV{REQUEST_METHOD} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} else {$buffer = $ENV{QUERY_STRING}}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{($name, $value) = split(/=/, $pair, 2);
 $value =~ tr/+/ /;
 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
 $in{$name} = $value;
}

$name=$in{'name'};
$email=$in{'email'};
$phone=$in{'phone'};
$password=$in{'password'};
$password2=$in{'password2'};
$referrer=$in{'referrer'};
print "Content-type:text/html\n";
if($ENV{'HTTP_COOKIE'} =~ /member=yes/) { #if registered already, redirect to main page
print "Location: $SiteURL/main.shtml\n\n";
exit}
#check fields
$err=0;
if ($name eq undef) {
print "\nYou haven't entered your name!<BR>";$err=1}
if ($email eq undef) {
print "\nYou haven't entered your email!<BR>";$err=1}
if ($phone eq undef) {
print "\nYou haven't entered your phone!<BR>";$err=1}
else {
    $ch = '\w\d\-\.\,\/\xc0-\xd6\xd8-\xf6\xf8-\xff';
    unless ($email =~ /^[${ch}]+\@[$ch]+(\.[${ch}]+)+$/) {
    print "\nPlease enter a valid email address!<BR>";$err=1}
}
open EMAILS, "emails.dat";
$/ = "\cC";
$emails=<EMAILS>;
$/ = "\n";
close EMAILS;
$lcemail=lc($email);
if ($emails=~/\n$lcemail\n/) {
print "\nEmail already in database!<BR>";$err=1}

if (($password eq undef) && ($password2 eq undef)) {
print "\nYou haven't entered your password!<BR>";$err=1}
if (($phone=~/$DBFieldSepChar/) || ($name=~/$DBFieldSepChar/) || ($email=~/$DBFieldSepChar/) || ($password=~/$DBFieldSepChar/)) {
print "\nCharacter '$DBFieldSepChar' in name, email, phone or password not allowed!<BR>";$err=1}
if (length($phone)>$DBPhoneLen) {
print "\nMaximum length for field 'phone' is $DBPhoneLen characters!<BR>";$err=1}
if (length($name)>$DBNameLen) {
print "\nMaximum length for field 'name' is $DBNameLen characters!<BR>";$err=1}
if (length($email)>$DBEmailLen) {
print "\nMaximum length for field 'email' is $DBEmailLen characters!<BR>";$err=1}
if (length($password)>$DBPasswordLen) {
print "\nMaximum length for field 'password' is $DBPasswordLen characters!<BR>";$err=1}
if ($password ne $password2) {
print "\nPasswords do not match!<BR>";$err=1}
if ($err == 1) {print "<BR>Press the back button on your browser and try again!";exit}


$filesize = (stat("$Database"))[7];
if ($filesize % $DBRecSize != 0) {die "Database processing error!"}
$users=$filesize / $DBRecSize;

#if there is no referrer, then assign to random member
srand;
unless (($referrer=~/\d/) && ($referrer!~/\D/)) {
do {
$referrer=int(rand($users-1))+2
} until ((ReadRecord($referrer))[$DBPassword] ne "");
};

#if (($referrer>$users) || ($referrer<1))  {$referrer=1}
@user="";

#for straight downline
$realreferrer=$referrer;
if ($users>0) {
@upline=ReadRecord($realreferrer);
$temprealref=$upline[$DBRealReferrer];
if ($upline[$DBStatus]==1) {}
elsif ((ReadRecord($temprealref))[$DBStatus]==1) {$referrer=$temprealref}
else {
if ($upline[$DBStatus]==0) {$referrer=$upline[$DBReferrer]};
}};
my $dr=0;

#increase direct referrals for referrer user
if ($users>0) {
  @user=ReadRecord($referrer);
  $user[$DBDirectReferrals]++;
  $dr=$user[$DBDirectReferrals];
  $refref=$user[$DBReferrer];
  WriteRecord($referrer,@user);
 
  if ($DirectDownlineDoubling) {
     #although we increased direct referrals for referrer user
     #we will give this referral to referrer's referrer if it's his 2nd or 4th
     #referral (downline doubling).
     $temp_referrer=$referrer;
     if (($dr eq "2") || ($dr eq "4")) {$referrer=$refref}
     if ($temp_referrer ne $referrer) {
   @user=ReadRecord($referrer);
   $user[$DBDirectReferrals]++;
   WriteRecord($referrer,@user);
     }
  }
}


#add new user
$lcemail=lc($email);
open EMAILS, ">>emails.dat";
print EMAILS "$lcemail\n";
close EMAILS;

$user[$DBName]=$name;$user[$DBPassword]=$password;$user[$DBEmail]=$email;

$user[$DBPhone]=$phone;

$user[$DBDirectReferrals]=$dr;
$user[$DBIndirectReferrals]="0";
$user[$DBReferrer]=$referrer;
$user[$DBRealReferrer]=$realreferrer;
$user[$DBBalance]="0";
$user[$DBStatus]="0";
#set hits=0 (("" and 0)== 0) for all programs
for($f=$DBProg1;$f<$PROGRAMS*3+$DBProg1;$f+=3) {$user[$f+2]=""}
$userid=AppendRecord(@user);
@refuser=ReadRecord($referrer);
$refname=$refuser[$DBName];
$refemail=$refuser[$DBEmail];
$refpass=$refuser[$DBPassword];

$unsubscribelink="$SiteURL/cgi-bin/unsubscribe.cgi?id=$userid&p=$password";

#send email greeting
$from='Team Residual Income admin <admin@teamresidualincome.com>';
$subject='Access to Your E-Book';
$message=qq~
Dear $name,

Your member ID# is $userid, and password is $password
You can use this user id and password to access the e-book any time
you like by simply visiting http://www.teamresidualincome.com and
clicking the login button.

Please give away this e-book to as many people as you can.
At then end of the e-book I will tell you how you can make an income
giving away this e-book for free.

Free e-book URL: $RootURL/cgi-bin/ref.cgi/$userid/

You can remove yourself from our system at any time by logging into
the members area and contacting us.  We will remove you from the
system upon your request.

Sincerely,
Team Residual Income admin
P.O. Box 32
Kuna, ID.  83634
$SiteURL/
~;

SendEmail($from,$email,$subject,$message,"-oi -t");

$unsubscribelink="$SiteURL/cgi-bin/unsubscribe.cgi?id=$referrer&p=$refpass";

#send email to sponsor
$subject='New signup!';

$message=qq~
Dear $refname,

Someone you referred just recieved a free e-book.

Member with ID#: $userid just signed up under you.


Name: $name
Phone: $phone
Email: $email

Keep Up The Good Work!



$SiteURL/


~;
SendEmail($from,$refemail,$subject,$message,"-oi -t");

#Insert into Listmail TRI Free List.
#LMinsert('4',$email);

$| = 1;
open CRON, ">>$crontab";
AppendLock(*CRON,0,0) or die "Error append locking CRON table!  $!\n";
for($f=1;eval('$email'.$f.'delay') ne undef;$f++) {
$delay = eval('$email'.$f.'delay');
$delay = $delay * 60 * 60;
$newtime=time() + $delay;
print CRON "$newtime $userid $f\n";
};
close CRON;
$| = 0;

#for recentsignups.cgi
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime(time);
if ($hour>=12) {$hour-=12;$m="PM"} else {$m="AM"};
$hour||=12;
if (length("$min")==1) {$min="0$min"};
$time="$hour:$min$m\n";
open DATA, "recentsignups.dat";
ReadLock(DATA,0,0);
@T=<DATA>;
close DATA;
shift @T;
$T[19]=$time;
foreach $line(@T) {chomp($line);$line.="\n"};
open DATA, ">recentsignups.dat";
WriteLock(DATA,0,0);
print DATA @T;
close DATA;

#this cookie will disallow to register twice
print "Set-Cookie: member=yes;path=/;expires=Tuesday, 12-Sep-30 10:00:00 GMT\n";
#ID to display at login screen and as referrer in registration page
print "Set-Cookie: loginid=$userid;path=/;expires=Tuesday, 12-Sep-30 10:00:00 GMT\n\n";

#show registration success screen

print qq~
<html><head><meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Congratulations!</title>
</head><body bgcolor="#FFFFFF">
<table border="0" width="100%" cellpadding="0" cellspacing="0" height="95%">
<tr><td width="100%" height="100%"><h2 align="center">Congratulations, you now have access to my e-book any time you like!<BR><BR>Your member ID# is $userid<BR>
<BR>You can now <A HREF="$SiteURL/login.shtml" target="_self">LOGIN</A> to access your copy!</H2>
<BR>
</H2>
</td></tr></table></body></html>~;
exit;
Title: Great !!!
Post by: BGSWebDesign on August 31, 2004, 06:53:56 am
Hi Dean, Gunther,

Wow, that's some powerful PERL scripting!  Gunther,
regarding your question, on line 9:
#require 'http://www.opportunityone.net/cgi-bin/LMinsert.pl';

You can't do a require like that from within PERL, you need
to point to the full path of the file, for example:
require "/home/usr/mydomain/cgi-bin/LMinsert.pl";

And when you do, I don't believe that require will work
with the required file containing the line at the top:
Code: [Select]
#!/usr/bin/perl
so you'll probably have to delete that line and rename
the file to something else when you include it.

Also I always use double quotes (around things) when making
that call, so not sure the single quotes will work, but probably will.

Line 206, 207 looks fine to me, it's the problem with the
require that's causing you errors, since you haven't required
the LMinsert.pl file correctly it's not available for use.

Dean, that configuration section of LMInsert:
Code: [Select]

   $allow_dupes = 1;
   # $overwrite_dupes = 1;
   # $ignore_dupes = 1;


Can you fill us in on  how that works exactly, I'm guessing
that allow_dupes inserts a brand new id beginning at the
first message in the sequence, and that overwrite_dupes will
overwrite the user and re-start them at the first message
in the sequence, is that right?   If so, then ignore_dupes just
ignores a duplicate and keeps the user where they were in
the sequence?

I'm fascinated by the capabilities of your modifications Gunther, but
haven't read through it deep enough - what are those three calls in
the beginning doing (what is in those cgi files?):

Code: [Select]

do 'sessions.cgi';
do "$Progcfg";
do 'sendemailfunc.cgi';
do 'delayedemails.cgi';


and what is that CRON code around line 209 doing?  
Code: [Select]

$| = 1;
open CRON, ">>$crontab";
AppendLock(*CRON,0,0) or die "Error append locking CRON table! $!\n";
for($f=1;eval('$email'.$f.'delay') ne undef;$f++) {
$delay = eval('$email'.$f.'delay');
$delay = $delay * 60 * 60;
$newtime=time() + $delay;
print CRON "$newtime $userid $f\n";
};
close CRON;
$| = 0;


Can you give us a brief rundown on what the code does major
sections), by line #?   I'd really appreciate it, as I believe some
of the things you are doing, I will want to do in the future.  

I love it, thanks... that LM Insert function is exactly what I've been
looking for, it will allow me to call a perl function in my daily cron
task to insert members into the LMP Database exactly where I want.[/code]
Title: Custom MySQL Insert Script - Perl
Post by: gwill23 on August 31, 2004, 07:12:56 am
The script I posted was written by http://www.rcdbs.com/.  I probably souldn't have posted it here but I need this to work.

Anyway I only edited the email text in this script and added the 3 lines we talked about.  If I can't get this to work I will have to just have it send an email to by LM automatically.

Anyway thanks for your help.  What you are saying is the LMinsert.pl needs to exist on the same box.  Currently the two systems live at different hosts.
Title: same box...
Post by: BGSWebDesign on August 31, 2004, 07:25:16 am
Gunther, Dean,

Dean, please read my long post above - a few quick questions
regarding configuration.

Gunther,
Quote
What you are saying is the LMinsert.pl needs to exist on the same box


Yes, that's right, you'll need to have the LMinsert.pl code on the
same box to do the require, you can't require a file on a
different server like that.  I'd still be curious what that other
code does as it would be very useful to me, just knowing
what the 3 cgi files you call do would be helpful, as I think
you're building an automated solution that would be useful
to many of us using LMP.
Title: Custom MySQL Insert Script - Perl
Post by: gwill23 on August 31, 2004, 07:38:12 am
I wish I could tell you I know what I am doing.  I don't.  I just backup everything hack away at it.  Sometimes it works sometimes it doesn't.  I posted the link to the guy who wrote the scripts you could always buy it and see that way.  He has been a big help so I don't want to give away any more of his code.  Sorry...I can't afford to have my only support to my downline club program mad at me :).

So I guess in the following config section of lminster.pl.  I need to change local host to some address that will allow me to access MYSQL from another hosting company.  Is that possible?


Quote
$sqlhost = 'localhost';
   $sqldb = 'dbname';
   $sqluser = 'username';
   $sqlpass = 'password';
Title: Custom MySQL Insert Script - Perl
Post by: BGSWebDesign on August 31, 2004, 07:44:08 am
Gunther,

Sure, I understand about the code, if it only does
things related to 'downline' building, and setting
that up, then it's not that interesting to me, I
thought that it was code you had written that
interfaced with LMP?   If it's not, then it doesn't
much matter - as it has nothing to do with how
you're interacting with LMP.

Thanks, and good luck, make that change to the
#require and move it to the same box and everything
should work fine  :D

You might be able to get away with changing the host
name from localhost to the other server, but I'm not
sure, I think I tried that once myself with SQL and it
didn't work.... the best bet is to move all of the code
for LMP to the same box, I hope that works for you?
Title: Split name variable
Post by: gwill23 on September 21, 2004, 06:54:46 am
I got this wonderful piece of code to work.  However, the system they sign up for only requires a name.  some put in first name only and some put both.  Is there a piece of code I could add to my register script to split the first and last name into two new variables called fname and lname?
Title: Custom MySQL Insert Script - Perl
Post by: DW on September 21, 2004, 01:31:17 pm
Gunther, name splitting code should be able to be found in one of ListMail's signup CGI scripts.

Brett, the configuration options are exactly as you guessed.  I thought this might be useful to some people.  :-)
Title: Custom MySQL Insert Script - Perl
Post by: gwill23 on October 08, 2004, 01:19:16 pm
Any idea on why these errors are poping up?  

Quote
[Fri Oct 08 14:09:59 2004] [error] [client 24.117.74.78] Premature end of script headers: register.cgi
[Fri Oct 08 14:09:59 2004] [error] [client 24.117.74.78] DBD::mysql::st execute failed: You have an error in your SQL syntax near 'membership@opportunityone.net'' at line 1 at /home/httpd/vhosts/teamresidualincome.com/cgi-bin/LMinsert.pl line 92.
[Fri Oct 08 14:09:59 2004] [error] [client 24.117.74.78] Undefined subroutine &main::mysql_fetch_row called at /home/httpd/vhosts/teamresidualincome.com/cgi-bin/LMinsert.pl line 96.
Title: Custom MySQL Insert Script - Perl
Post by: DW on October 08, 2004, 04:51:46 pm
Hmm, no I'm not sure.  Try making sure the script (LMinsert.pl) is CHMOD to 755 and that the path to Perl, on the first line, is correct.
Title: Custom MySQL Insert Script - Perl
Post by: gwill23 on October 11, 2004, 10:37:25 am
ok it looks like I had to install DBI and DBD::mysql on my server.   Plesk install didn't do that.

I have those installed and the file has the right chmod on it.  I still get the following errors.

Quote
[Mon Oct 11 11:31:26 2004] [error] [client 24.117.74.78] Premature end of script headers: register.cgi
[Mon Oct 11 11:31:26 2004] [error] [client 24.117.74.78] DBD::mysql::st execute failed: You have an error in your SQL syntax near 'test4@opportunityone.net'' at line 1 at /home/httpd/vhosts/teamresidualincome.com/cgi-bin/LMinsert.pl line 92.
[Mon Oct 11 11:31:26 2004] [error] [client 24.117.74.78] Undefined subroutine &main::mysql_fetch_row called at /home/httpd/vhosts/teamresidualincome.com/cgi-bin/LMinsert.pl line 96.



The line number referenced don't make since.  I have the the duplicate section turned off I think.

Quote
#$allow_dupes = 1;
   # $overwrite_dupes = 1;
   $ignore_dupes = 1;


Does anyone have this working?
Title: bugs in code...
Post by: BGSWebDesign on October 11, 2004, 11:36:17 am
Hi Gunther,

Yes, I ran into that myself, the code is buggy, line 92 reads:
Code: [Select]
$cmd = "select id from lm_users where list = '$li''and email like '$em'";

Should be replaced with:
Code: [Select]
$cmd = "select id from $utable where list = '$list' and email like '$em'";

$utable is used all over in this code and then left undefined, at the top you need to define $utable like this:
Code: [Select]
$utable = 'lm_users';

I put it right after $sqldb =

There are other problems with the code, when setting up the defined vars - uncomment ALL of them, and define (set to 1) only one of them, like this:
Code: [Select]

   $allow_dupes = 0;
   $overwrite_dupes = 0;
   $ignore_dupes = 1;


Just make sure you only set one of those to 1.

I don't like the way the calls are made to MySQL through the DBI interface either, there needs to be code for attempting the call several times, not just 'execute'...  but that's just my opinion, also I couldn't get that last line of MySQL defined properly in a string, and had to use what was there, does anyone know how to define this to make it work:
Code: [Select]

$dbh->do('INSERT INTO lm_users VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',undef,('null',$uid,$list,"$fn","$ln","$em","$u1","$u2","$u3","$u4","$u5","$u6","$u7","$u8","$u9","$u10","$sq","$de",'1',$da,"$ip","$ref",'1','0'));


I'd like to use something like below but can't get it defined to work properly, any ideas?:
Code: [Select]

$cmd = "INSERT INTO lm_users VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" . ",undef,('null',$uid,$list,\"$fn\",\"$ln\",\"$em\",\"$u1\",\"$u2\",\"$u3\",\"$u4\",\"$u5\",\"$u6\",\"$u7\",\"$u8\",\"$u9\",\"$u10\",\"$sq\",\"$de\",'1',$da,\"$ip\",\"$ref\",'1','0'";


Dean, what'd you have for breakfast?   Seems that code is buggy in a few places and wasn't tested properly (doesn't sound like you)!
Title: Custom MySQL Insert Script - Perl
Post by: gwill23 on October 11, 2004, 12:27:36 pm
Those fixes worked.  Thanks Webshaman!
Title: Custom MySQL Insert Script - Perl
Post by: gwill23 on October 11, 2004, 04:29:18 pm
ok I just finished partly supercharging the script and it is working great except for one thing.  

First of all I needed to split a variable in my register.cgi script from my free ebook registration page http://www.teamresidualincome.com/

These two parts split the name in half.  Too bad for those with more than two names, but it will work most times.:

Added near the top:
Quote
# encode function
sub encode {
  my $str = shift || '';
  $str =~ s/([^\w.-])/sprintf("%%%02X",ord($1))/eg;
  $str;
}


Added where it makes sence notice is needs the $name to be defined so it can work on it.

Quote
$spos = index($name,' ');
    if($spos>=0){
     $fn = substr($name,0,$spos);
     $ln = substr($name,$spos+1,length($name)-$spos-1);
    }


Now I could all LMInsert.pl like this:
Quote
#Listmail Signup Process to Free List.
LMinsert('1',$email,$fn,$ln,$userid,$phone,$referrer,$refname,$refemail,$unsubscribelink,,,,,'1','0','Unknown','http://www.teamresidualincome.com/cig-bin/register.cgi');


How I put the code in and made it work was a true act of inspiration.  I didn't really know what I was doing.  Funny thing is it worked the first time :).  Thank the lord :).

Now for the issue.  There is something in the LMInsert.pl that causes my ref URL at the end to show unknown.  I thought it was the default section quoted below but commenting that out leaves the ref URL blank instead.

Quote
$list = $_[0];   $em = $_[1];   $fn = $_[2];   $ln = $_[3];   $u1 = $_[4];
        $u2 = $_[5];   $u3 = $_[6];    $u4 = $_[7];   $u5 = $_[8];   $u6 = $_[9];
        $u7 = $_[10];   $u8 = $_[11];   $u9 = $_[12];   $u10 = $_[13];   $sq = $_[14];
   $de = $_[15];   $ip = $_[16];   $ref = $_[17];

   # default seq
   if(!$sq){ $sq = '1'; }
   # default delay
   if(!$de){ $de = '0'; }
   # default IP
   if(!$ip){ $ip = 'Unknown'; }
   # default ref url
   if(!$ref){ $ref = 'Unknown'; }


Any Ideas Webshaman or DW?
Title: Custom MySQL Insert Script - Perl
Post by: DW on October 12, 2004, 07:42:51 am
To be honest, this was one of my first Perl scripts that accessed a MySQL database.  I am not very experienced with optimizing these calls or making them easy to edit.

I am not sure about the referring URL problem.  I could have made a mistake in the code.  One way to test it is to output the variables:
Quote
$list = $_[0];   $em = $_[1];   $fn = $_[2];   $ln = $_[3];   $u1 = $_[4];
        $u2 = $_[5];   $u3 = $_[6];    $u4 = $_[7];   $u5 = $_[8];   $u6 = $_[9];
        $u7 = $_[10];   $u8 = $_[11];   $u9 = $_[12];   $u10 = $_[13];   $sq = $_[14];
   $de = $_[15];   $ip = $_[16];   $ref = $_[17];

After the above code, try this:
Quote
print("ref=".$ref);
Title: wget or lminsert via perl?
Post by: BGSWebDesign on December 17, 2004, 11:00:08 am
Hi,

Back on this topic, I'm setting up my signup-listxx calls and was wondering if it's better (more efficient) to make the calls in my .procmailrc file using wget to call signup.php within signup-listxx, or would it be more efficient to call lminsert from within signup-listxx?

It seems to me that the call to lminsert would be more efficient, since we're already being called by perl when the call is made?  Any insight into this?  I don't feel comfortable using the 'wget' call as that has to run via the command line and it may be less secure too?
Title: bugs in code...
Post by: inkras on April 20, 2005, 05:29:11 am
I have done these corrections.
But server reports about a following errors:
Undefined subroutine &main::mysql_fetch_row called at /home/.../mail/insert/LMinsert.pl line 97.

Thank
Pavel
Title: Custom MySQL Insert Script - Perl
Post by: DW on April 27, 2005, 11:38:24 pm
Pavel/inkras,

Try replacing this:
Code: [Select]
  if(!$allow_dupes){
                $cmd = "select id from lm_users where list = '$li''and email like '$em'";
                $quer = $dbh->prepare($cmd);
                $quer->execute();
                $rows = $quer->rows;
      #  duplicate found..
      if($rows>0){
         list($xid,$xcnf)=mysql_fetch_row($result);

With this:
Code: [Select]
  if(!$allow_dupes){
                $cmd = "select id,cnf from lm_users where list = '$li''and email like '$em'";
                $quer = $dbh->prepare($cmd);
                $quer->execute();
                $rows = $quer->rows;
      #  duplicate found..
      if($rows>0){
         my ($xid,$xnf) = $quer->fetchrow_array();

This is untested - I don't have time tonight.  Let me know if it doesn't work and I will test it thoroughly.

Brett/webshaman,

Quote from: "webshaman"
Back on this topic, I'm setting up my signup-listxx calls and was wondering if it's better (more efficient) to make the calls in my .procmailrc file using wget to call signup.php within signup-listxx, or would it be more efficient to call lminsert from within signup-listxx?

It seems to me that the call to lminsert would be more efficient, since we're already being called by perl when the call is made? Any insight into this? I don't feel comfortable using the 'wget' call as that has to run via the command line and it may be less secure too?

You're right - it would be more efficient to call lminsert from within the signup-listX.cgi scripts.  The only reason I use the (quite inefficient) wget calls in the .cgi scripts is to make installation easier - so you don't have to enter your MySQL details in both PHP and Perl.  This approach can cause problems with bounces, mostly, because it can flood the web server. I should probably think about optimizing this soon.  Perhaps I could read the ListMail config.php via Perl by having you set a simple relative path.

Regards
Title: Does this need any change for ver. 1.8x?
Post by: BGSWebDesign on September 06, 2005, 07:08:35 am
Hi,

Regarding this:
Quote
Copy and paste the following code into a file named LMinsert.pl

Please read the notes near the top of the file for information about usage.

Code:


Does this need any changes to run with ver 1.8x?   I don't believe it does, as I'm using it now and it seems to work, but something is a funny, I'm getting fewer records added nightly to my lists?   Previously one list averaged about 240, and now I'm getting 160, another list averaged about 60-70 before and now I'm getting 50?

Any ideas on why this might be happening, or just that the number of visitors is down?
Title: Custom MySQL Insert Script - Perl
Post by: DW on September 08, 2005, 06:22:20 am
I have noticed a decrease in traffic lately - I think it's because everyone is/was on vacation.  Apart from the standard tests, if you have access to your site's web server logs you might be able to take a closer look and verify whether or not there are reported errors.  You can also add the "-w" option to the top of the script to possibly output extra debug info.

#!/usr/bin/perl -w

Regards
Title: Custom MySQL Insert Script - Perl
Post by: BGSWebDesign on September 12, 2005, 10:03:13 am
Hi DW,

No, I think it's more than this, did you change the way the COUNT displays in the upper Right of Screen, or did you change the SQL for that COUNT by any chance?

Code: [Select]
Active Users 1-20 of 6409

I started going through my ENTIRE logs of entered users, but I don't want to go that far yet, I can do it for an entire day, but it seems like you may have changed how this Count appears and that NOW (vers. 1.8x) it is NOT displaying dupes that appear here and in other lists?  Or something else is wrong?

If that's not it, I don't know what to do except to do a Search on an entire day of entry - about 70 on one list, and see if they all appear, if they do, then the Count is not Updating properly from day to day?

Any other ideas - as I'm showing a good 20-30% difference (less) from what appears on the Count on my screen from what I am showing has been added - from previous day...
Title: Custom MySQL Insert Script - Perl
Post by: DW on September 13, 2005, 05:18:12 am
Brett,

So you're saying the number of users in the User Database as compared to the number shown in the Dailymail Report is less?  I just want to make sure all bases are covered - are you sure you're not comparing the "totals" across all lists in the dailymail report with the users on a single list?

I wish I could say I have an idea about what's going on.  If you can provide more information through further testing please let me know.  One idea might be to send you an email every time someone subscribes and is inserted with the LMinsert.pl function.  (This would take a little custom perl code).  It might be worthwhile to compare, using PhpMyAdmin, a user entry made by LMinsert.pl and one made, say, by manually adding a user to make sure there are no differences.

Regards
Title: Custom MySQL Insert Script - Perl
Post by: BGSWebDesign on September 13, 2005, 06:07:56 am
Hi DW,

Quote
users in the User Database as compared to the number shown in the Dailymail Report is less?


No, what I do is keep logs of users that are entered via LMInsert, those logs show me the email address/names of each user that is passed into LMP using the LMInsert function call (via a cronjob).

Those logs are NOT matching the COUNT that appears in the upper right, for example the difference on these two lists which I inserted last night is as follows:
List1 - 61 inserted, 96 in logs
List2 - 191 inserted, 253 in logs

So, you see, I've been going to my logs, and searching the database on the email address, I started going through the entire List1 yesterday, but posted this message first, so today, I could go through the entire 96 entries, and see which, if any do NOT appear.  I didn't find any yesterday that did not appear (in about 10 tries).

If all 96 (that are in my logs) also appear in LMP, then the COUNT (in the upper right) is not accurate for some reason??

I'll do that today, and let you know what I find...
Update
Ok, I just went through all 96 entries that were LMinserted into List1, and they are ALL in the database, so that tells me that there is a problem with the COUNT that appears at the top, or the Bounces/Removes are making up the 35 difference between the actual that were Inserted, and the total count - this MIGHT be a possibility, but I don't believe it is with List2, as that list does NOT have any followups being emailed, which means NO bouncing would take place, and I don't believe that 62 users have bounced/removed themselves from the list....  

What does that leave - I can try a DailyMail report to see....  any other suggestions?