Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Perl/Cron Error

Posted on 2004-09-15
7
Medium Priority
?
242 Views
Last Modified: 2008-02-26
Hi all,
Thanks in advance for your help.

I keep getting this error:
DBD::mysql::st fetchrow_array failed: fetch() without execute() at /home/a1classi/public_html/warn.cgi line 57

Here is the code it is suppose to send out a warning email:

#!/usr/bin/perl

use CGI;
use DBI;


$host = "localhost";
$port = "****";
$db_name = "****";
$mysqlusername = "****";
$mysqlpassword = "****";
$sema = "/usr/sbin/sendmail";
############WS HITS############



####GETS MYSQL DATABASE#########
$dbh = DBI->connect("DBI:mysql:database=$db_name;host=$host;port=$port",$mysqlusername,$mysqlpassword) ||  die "cannot connect to database";

$t = time;





####GETS PEOPLE TO SEND EMAIL TO#########
$query = "SELECT email, idnum, password FROM classifiedads WHERE expires < $t AND warned = 0";
$sth = $dbh->prepare($query);
$sth->execute;



while(@row = $sth->fetchrow_array) {

####MARKS THE ACCOUNT AS HAVING BEEN WARNED#########
$sth = $dbh->prepare("UPDATE classifiedads SET warned = '1' WHERE idnum = '$row[1]'");
$sth->execute;
$sth->finish();
                              
                              
$expiredmess = "email message";
            
####SENDS EMAIL#########            
    open (MESSAGE,"|$sema -t");
    print MESSAGE "To: $row[0]\n";
    print MESSAGE "From: support\@\n";
    print MESSAGE "Subject: message\n\n";
    print MESSAGE "$expiredmess\n\n";
    close (MESSAGE);


            }
            
            
            
exit;
0
Comment
Question by:cortecds
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 10

Expert Comment

by:Jay Toops
ID: 12076923
This is suspect
$query = "SELECT email, idnum, password FROM classifiedads WHERE expires < $t AND warned = 0";
$sth = $dbh->prepare($query);
$sth->execute;

$t is probably returning somthing that can't be interpreted as a date or
maybee even results in invalid sql

JAY
0
 

Author Comment

by:cortecds
ID: 12078118
Hi,
Thanks for your help the $t appears to work because I guess I failed to mention that the script works it just emails me that error.

So if I have an account that is expiring then it finds it and marks it as warned and sends out the warning.

But it also tells me:
DBD::mysql::st fetchrow_array failed: fetch() without execute() at /home/a1classi/public_html/warn.cgi line 57

But line 57 is actually the  liner that says:
close (MESSAGE);


Thanks!
0
 
LVL 10

Expert Comment

by:Jay Toops
ID: 12079029
maybee you need to flush the message first??

Jay
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cortecds
ID: 12079123
Not sure what you mean by flush
0
 
LVL 1

Accepted Solution

by:
elmic earned 2000 total points
ID: 12095370
The problem I see is that your redeclaring the STH in the middle of the fetch of STH:

while(@row = $sth->fetchrow_array) {
     ####MARKS THE ACCOUNT AS HAVING BEEN WARNED#########
>     $sth = $dbh->prepare("UPDATE classifiedads SET warned = '1' WHERE idnum = '$row[1]'");
>     $sth->execute;
>    $sth->finish();


}

Change the inner STH to somthing else like STHA. Here an example, I also put a my declare which is a good habit you might want to start doing:

while(@row = $sth->fetchrow_array) {

      ####MARKS THE ACCOUNT AS HAVING BEEN WARNED#########
      my $stha = $dbh->prepare("UPDATE classifiedads SET warned = '1' WHERE idnum = '$row[1]'");
      $stha->execute;
      $stha->finish();

      $expiredmess = "email message";
      
      ####SENDS EMAIL#########          
      open (MESSAGE,"|$sema -t");
      print MESSAGE "To: $row[0]\n";
      print MESSAGE "From: support\@\n";
      print MESSAGE "Subject: message\n\n";
      print MESSAGE "$expiredmess\n\n";
      close (MESSAGE);
}
0
 

Author Comment

by:cortecds
ID: 12103121
DUH :P I can't believe I didn't catch that.
Sometimes you can't see the forrest through the trees.
THANKS!
0
 
LVL 1

Expert Comment

by:elmic
ID: 12128905
Happens to all of us.... :)
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question