We help IT Professionals succeed at work.
Get Started

If statement not working correctly

jefftsnyder asked
Last Modified: 2013-11-05
I need some help with this script.

The connection to the database works, the query works and the emailing portion of the script also works.

My problem is that the if /while statements do not seem to be reading correctly.

The query is supposed to run, then if the count results are 100 or greater send an email. The problem is that it send the email no matter what the result is.

Any thoughts/suggestions? I am probably overlooking a simple issue, but I need another pair of eyes on this one!
use DBI;
use Mail::SendEasy;
#$cgi = new CGI();
my $data_src="DBI:ODBC:ConnectFbServerW";
my $username="XXXXXXXX";
my $password="XXXXXXXX";
my $dbh=();
my $sth=();
$dbh=DBI->connect("$data_src","$username", "$password",{RaiseError => 1,PrintError => 1}) || die("Database connection not made: $DBI::errstr\n");
my $sth = $dbh->prepare("select COUNT(*) from TRANSMITSTUDYLIST");
    while(@dat = $sth->fetchrow) {
        my $mail = new Mail::SendEasy 
  				smtp => 'XXXXXXXXXX' ,
  				user => 'XXXXXXXx@XXXXXX' ,
  				pass => 'XXXXXXXX' 
  			) ;
  my $status = $mail->send(
  from    => 'XXXXXXXx@XXXXXX' ,
  from_title => 'Jeff' ,
  reply   => 'XXXXXXXx@XXXXXX' ,
  error   => 'XXXXXXXx@XXXXXX' ,
  to      => 'XXXXXXXx@XXXXXX' ,
  subject => "text here" ,
  msg     => "More txt here " ,
  											) ;
  if (!$status) { print $mail->error ;}
else    {
 print "Query failed due to ", $sth->errstr(),"\n";

Open in new window

Watch Question
Expert of the Year 2008
Top Expert 2008
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE