in reply to SQL - Subroutine always returning true
The reason for your routine returning 0 is that $mid was zeroed before it was tested. OK. I see that you found it.
On a side note, I would like to point out a few things that may be source of some trouble for your code in future.
Here is how I would write this routine.
# untested sub member exists { my ($dbh, $email, $mid) = @_; my $query = qq{ SELECT COUNT(*) FROM ML_Subscribers WHERE S_Email = ? AND MID = ? }; my $sth = $dbh->prepare($query); $sth->execute ($email, $mid); my ($count) = $sth->fetchrow_array(); $sth->finish(); return $count; } my $dbh = DBI->connect("blah blah blah") or die "..."; print "Joe exists\n" if member_exists($dbh, "joe", 12); print "Fred is there\n" if member_exists($dbh, "fred", 16); # the rest of your application here. $dbh->disconnect;
HTH
_ _ _ _ (_|| | |(_|>< _|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: SQL - Subroutine always returning true
by devslashneil (Friar) on Jul 11, 2003 at 07:32 UTC | |
|
Re: Re: SQL - Subroutine always returning true
by nite_man (Deacon) on Jul 11, 2003 at 11:58 UTC |