Few things that I can see.  I'm sure others will give you more ideas.

On 7/27/05, David Foley <[EMAIL PROTECTED]> wrote:
> Hi Guys,
>                Can you please look at the below script. The SQL query
> works on it's own in separate script. But not when it is put into the
> "for" loop in this script
> . Any ideas??
> 
> Thanks,
> David
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------
> #!/usr/bin/perl -w
> 
> #Reduce scripting errors
> use strict;
> 
> #Call relevant modules
> use Net::POP3;
> use DBI;
> 
> #Connect to POP3 server
> my $pop3server = Net::POP3->new('****server****');
> 
> #Login to POP3 server
> $pop3server->login('****user****', '****pass****');
> 
> #How many messages there is
> my $lastm = ($pop3server->popstat)[0];
> 
No error checking up to this point.  What happens if the connection to
the server or authentication fails?

> #Connect to MySQL database on localhost
> my $MySQL = DBI->connect
> ("DBI:mysql:NOD32:localhost","****","***************") or die " Could
> not connect to MySQL database on localhost\n";
> 
> #Get and process mail
> for my $messageID (90){
What exactly is this supposed to do?  If you just run this
for my $messageID (90){
 print $messageID . "\n";
}
It outputs nothing..
> 
> my $MFH = $pop3server->getfh($messageID);
What happens when there is an error getting the message here?
> 
> #Extract values
> my $name = '';
> my $refno = '';
> my $userpass = '';
> my $wtable = '';
> 
> while(<$MFH>) { if ( $_ =~ m/UserName:Password=/ ) {(undef, $userpass) =
> split /=/, $_;}
>         if ( $_ =~ m/person:/ ) {(undef, $refno) = split /:/, $_;}
>         if ( $_ =~ m/Clients_name:/ ) {(undef, $name) = split /:/, $_;}
$name is not used anywhere. Do you need the above line?
> 
>           }
> 
> if($refno =~ /NRS/) {$wtable = 'RSorders2005';} else{ $wtable =
> 'SUorders2005';};
> 
> chomp($userpass);
> $MySQL->quote($userpass);
The above line does not do what you expect it to do.

> $refno =~ s/^\s//;
> 
> #SQL Query 1
> my $SQLQ1a = "UPDATE $wtable SET UsernamePassword  = '$userpass' WHERE
> RefNo = '$refno'";
> print "$SQLQ1a";
> 
> 
> #SQL Query 1 HANDLE
> my $SQLQ1 = $MySQL->prepare($SQLQ1a);
> 
> #Exexute SQL Query 1
> $SQLQ1->execute();
> 
> }
> 
> 
You only are calling 2 different database statements.  Would it make
sense to prepare them on the top then call them in the for loop? 
Something like:
my $RSOrders = $MySQL->prepare("update RSorders2005 set
UsernamePassword = ? where RefNo = ?");
my $SUOrders = $MySQL->prepare("update SUorders2005 set
UsernamePassword = ? where RefNo = ?");

Then in the for loop..
   if($refno =~ /NRS/) {
      $RSOrders->execute($userpass, $refno) or die "Unable to update
tables: ". $MySQL->errstr."\n";
      $RSOrders->finish;
   } else{ 
      $SUOrders->execute($userpass, $refno) or die "Unable to update
tables: ". $MySQL->errstr."\n";
      $RSOrders->finish;
   }


HTH

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to