SPUG: Two errors I need hashing out

Susanne Bullo sweetsue at sweethomes.com
Tue Jan 15 11:25:49 CST 2002

Being new, I still haven't a complete clue as to what I'm doing.  The listed
program is giving the following two errors:

print on closed filehandle main::FILE at sunday line 61.
DBD::mysql::st execute failed: Duplicate entry '127' for key 1 at sunday
line 79.

I'm at a loss as to what the first one is.  The second one I'm thinking has
to do with number assigning within the database but I'm not completely sure
(there is an id of 127 within the database but that is under id and not
under uid which seems to be what "key 1" is referencing).

If anyone has a soft spot for a newbie and wants to help me out, I'd
appreciate it!

#!/usr/bin/perl -w
use Time::Local;
use POSIX qw(mktime);
use DBI;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
sub get_date {
@days = ('Sunday','Monday','Tuesday','Wednesday',
@months = ('January','February','March','April','May','June','July',
($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
$time = sprintf("%02d:%02d",$hour,$min);
if ($year < 50){
$year += 2000;
else {
$year += 1900;
$date = "$days[$wday], $months[$mon] $mday, $year at $time";
$mon2 = $mon + 1;
$date2 = "$mon2/$mday/$year";
$date3 = "$mon2.$mday.$year";
my $buffer = '';
my $buffer2 = '';
my $buffer3 = '';
my $host = 'localhost';
my $database = 'safelist';
my $username = 'admin';
my $password = 'srb6653';
my $ua = new LWP::UserAgent();
my $dbh = DBI->connect("DBI:mysql:$database", $username, $password) || die
"Failed DBI connect(): $!\n";
my $query = "SELECT safelists.email_to, safelists.username,
safelists.password, email_txt.email_subject, email_txt.email_text,
safelists.uid, members.email from safelists, schedule, email_txt, members
where email_txt.id = schedule.SUN and schedule.system_name =
safelists.system_name and members.id = safelists.uid and
email_txt.email_subject != ''";
$buffer .= "===> Executing Query: $query\n\n";
my $sth = $dbh->prepare($query);
my $rc = $sth->execute();
id,$email) = $sth->fetchrow_array) {
my $url = "http://$email_to?action=Send This
$email_text =~ s/\\//g;
my $req = HTTP::Request->new(GET=>$url);
my $file_path = "./members/data/$username/$system_name/$date3.txt";
my $resp = $ua->request($req, $file_path);
my $sec_file_path = "members/data/$username";
my $outfile = "index.html";
my $filename = "$sec_file_path/$outfile";
open (FILE,">>$filename");
Line 61 -->{ print FILE "<a href=$sec_file_path>Problem on $date3</a>"; }
close (FILE);
my $query2 = "SELECT safelists.uid, schedule.system_name from safelists,
schedule where schedule.system_name = safelists.system_name and schedule.SUN
!= '0'";
$buffer2 .= "===> Executing Query: $query2\n\n";
my $sth = $dbh->prepare($query2);
my $rc = $sth->execute();
while (my($uid,$system_name) = $sth->fetchrow_array) {
my $datestamp = $date2;
my $timestamp = $time;
my $query3 = "INSERT into reports (uid, system_name, last_success_run, id)
values ('$uid', '$system_name', '$datestamp at $timestamp', '')";
$buffer3 .= "===> Executing Query: $query3\n\n";
my $sth = $dbh->prepare($query3);
Line 79 -->my $rc = $sth->execute();
undef $sth;

Susanne Bullo - Sweet Homes
DirectTV DSL
Get Paid to Read Email!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/archives/spug-list/attachments/20020115/d7fc129b/attachment.htm

More information about the spug-list mailing list