I wrote the quick, poorly-written, yet functioning code below to interface with a database of appointments. The intent of the script is to send me a notice via email a day before the event occurs. It doesn't seem to mater what I do, I can't make the script send me an email ONLY when the query is true. I'm open to any ideas.

#!/usr/bin/perl use Date::Manip; use DBI; use strict; my $mailprog = '/usr/lib/sendmail'; my $tomorrow=&DateCalc("today","+1day"); my $year = substr $tomorrow, 0, 4; my $month = substr $tomorrow, 4, 2; my $day = substr $tomorrow, 6, 2; my $tomorrow = $year."-".$month."-".$day; my ($dsn) = "DBI:mysql:andrewkmitchell_com:localhost"; # data source n +ame my ($user_name) = "akm2"; # user name my ($password) = "merlin2562"; # password my ($dbh, $sth); # database and statement handles my (@ary); # array for rows returned by query # connect to database $dbh = DBI->connect ($dsn, $user_name, $password, { RaiseError => 1 }) +; # issue query my $query = qq{ SELECT id, name, event_date, start_time, end_time, des +cription FROM ltw_events WHERE event_date="$tomorrow" }; $sth = $dbh->prepare ( $query ); $sth->execute (); open(MAIL,"|$mailprog -t"); print MAIL "To: akm2\@merlin-internet-services.net\n"; print MAIL "From: root\@merlin-Internet-Services.net (Re-minder)\n"; print MAIL "Subject: Reminder for Tomorrow ($tomorrow)\n"; print MAIL "X-Priority: 1 (Highest)\n\n"; print MAIL "This in an automatic message generated by Re-Mind. The pu +rpose of this message is to remind you of event(s) you have scheduled + for tomorrow ($tomorrow).\n\nEvents are listed below:\n\n"; while (@ary = $sth->fetchrow_array ()) { print MAIL join ("\t", @ary), "\n"; } print MAIL "\nEND OF SCHEDULED EVENTS!\n"; close(MAIL); $sth->finish (); $dbh->disconnect (); exit (0);

Andrew Kenton Mitchell
Andrew@AndrewKMitchell.com


In reply to Testing to see if a MySQL query is true by akm2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.