Author Topic: Custom MySQL Insert Script - Perl  (Read 17188 times)

DW

  • Administrator
  • Posts: 3787
    • View Profile
    • https://legacy.listmailpro.com
Custom MySQL Insert Script - Perl
« 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
Dean Wiebe
ListMailPRO Author & Developer - Help | Support | Hosting

gwill23

  • Posts: 50
    • View Profile
    • http://www.residualenterprises.com
Custom MySQL Insert Script - Perl
« Reply #1 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;

BGSWebDesign

  • Posts: 625
    • View Profile
    • http://www.bgswebdesign.com
Great !!!
« Reply #2 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]
Thanks,
-Brett
http://www.bgswebdesign.com/Contact-Us.php

*** I do custom List Mail Pro installations ***
Contact me through my website (above)

gwill23

  • Posts: 50
    • View Profile
    • http://www.residualenterprises.com
Custom MySQL Insert Script - Perl
« Reply #3 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.

BGSWebDesign

  • Posts: 625
    • View Profile
    • http://www.bgswebdesign.com
same box...
« Reply #4 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.
Thanks,
-Brett
http://www.bgswebdesign.com/Contact-Us.php

*** I do custom List Mail Pro installations ***
Contact me through my website (above)

gwill23

  • Posts: 50
    • View Profile
    • http://www.residualenterprises.com
Custom MySQL Insert Script - Perl
« Reply #5 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';

BGSWebDesign

  • Posts: 625
    • View Profile
    • http://www.bgswebdesign.com
Custom MySQL Insert Script - Perl
« Reply #6 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?
Thanks,
-Brett
http://www.bgswebdesign.com/Contact-Us.php

*** I do custom List Mail Pro installations ***
Contact me through my website (above)

gwill23

  • Posts: 50
    • View Profile
    • http://www.residualenterprises.com
Split name variable
« Reply #7 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?

DW

  • Administrator
  • Posts: 3787
    • View Profile
    • https://legacy.listmailpro.com
Custom MySQL Insert Script - Perl
« Reply #8 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.  :-)
Dean Wiebe
ListMailPRO Author & Developer - Help | Support | Hosting

gwill23

  • Posts: 50
    • View Profile
    • http://www.residualenterprises.com
Custom MySQL Insert Script - Perl
« Reply #9 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.

DW

  • Administrator
  • Posts: 3787
    • View Profile
    • https://legacy.listmailpro.com
Custom MySQL Insert Script - Perl
« Reply #10 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.
Dean Wiebe
ListMailPRO Author & Developer - Help | Support | Hosting

gwill23

  • Posts: 50
    • View Profile
    • http://www.residualenterprises.com
Custom MySQL Insert Script - Perl
« Reply #11 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?

BGSWebDesign

  • Posts: 625
    • View Profile
    • http://www.bgswebdesign.com
bugs in code...
« Reply #12 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)!
Thanks,
-Brett
http://www.bgswebdesign.com/Contact-Us.php

*** I do custom List Mail Pro installations ***
Contact me through my website (above)

gwill23

  • Posts: 50
    • View Profile
    • http://www.residualenterprises.com
Custom MySQL Insert Script - Perl
« Reply #13 on: October 11, 2004, 12:27:36 pm »
Those fixes worked.  Thanks Webshaman!

gwill23

  • Posts: 50
    • View Profile
    • http://www.residualenterprises.com
Custom MySQL Insert Script - Perl
« Reply #14 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?