On Fri, 8 Nov 2002 17:29:13 -0500 Jeff Herrin <[EMAIL PROTECTED]> wrote:

> I'm having a pretty basic issue. I do PHP and am Perl has always been
> pretty awkward for me. I'm successfully querying from my mySQL database.
> I'm also successfully looping through the returned results. My problem
> is with the IF statement in the loop.... The if ($html < 1)  part. $html
> is a column name fromteh database and I just need it to chack if it's 1
> or 0 and send the appropriate email to the address currently in the
> loop. I'm sure the problem is that I'm jsut not referencing the $html
> column value correctly. 
> Thanks in advance your assistance.
> 
> 
> my $dbh = DBI->connect($dsn, $db_user_name, $db_password);

# You aren't checking for errors
my $dbh = DBI -> connect( $dsn, $db_user_name, $db_password,
   { "AutoCommit" => 0, "PrintError" => 0, "RaiseError" => 1 } );

> my $sth = $dbh->prepare(qq{
>     SELECT email, html FROM user WHERE newsletter > 0
> });
> $sth->execute();

# You aren't putting anything into $html
# For effeciency, I prefer bind_columns() and fetch()
my ( $email, $html );
$sth -> bind_columns( \( $email, $html ) );
while ( $sth -> fetch )

># while (my ($email) = 
>#     $sth->fetchrow_array()) 
> {
> open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
> 
> if ($html < 1) {
> 
> print SENDMAIL "To: $email \n";
> print SENDMAIL "From: $reply_to\n";
> print SENDMAIL "Subject: $subject\n";
> print SENDMAIL "Content-type: text/plain\n\n";
> print SENDMAIL "$content_plain";
> close(SENDMAIL);
> 
> } else {
> print SENDMAIL "To: $email \n";
> print SENDMAIL "From: $reply_to\n";
> print SENDMAIL "Subject: $subject\n";
> print SENDMAIL "Content-type: text/html\n\n";
> print SENDMAIL "$content_html";
> close(SENDMAIL);
> }
> 
> }

# It is usually a good idea to explicitly close the database
$dbh -> disconnect;

-- 
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.tuxedo.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.


Reply via email to