perlquestion
devslashneil
Hi Monks,
<br>
I have written a subroutine to test if a user is in the database or not. It returns 1 if the user is in the database and 0 if the user is not in the database.
<br>
Here is the code i have written:
<code>
sub member_exists
{
my ($email,$mid) = @_;
chomp ($email,$mid);
my $db = "nMail";
my $sock = "/tmp/mysql.sock";
my $user = "";
my $pass = '';
my $dsn = "DBI:mysql:$db;mysql_socket=$sock";
my $mid = ();
my $dbh = DBI->connect($dsn,$user,$pass);
my $sth = $dbh->prepare("SELECT S_Email,MID FROM ML_Subscribers");
$sth->execute() || die "Error: Could not get mailing list data\n";
while (my @row = $sth->fetchrow_array) {
if($row[0] eq $email and $row[1] == $mid){
return 1;
}
}
$sth->finish();
$dbh->disconnect();
return 0;
}
</code>
However this will always return 0 for all cases. When i remove <code> and $row[1] == $mid</code> it works fine, but i need the $email and $mid to be the same. I've tried changing "==" to "eq" but that doesn't work either.<br><br>
I have also tried the sql statement: <code> SELECT S_Email,MID FROM ML_Subscribers WHERE MID = '$mid' AND S_Email = '$email' </code> and then tested if <code> $row[0] </code> is true. <br> None of these things worked so i am pretty stuck for ideas.
<br>
I'm sure it has to be something stupid i am over looking, i would appreciate any input.
<br>
Cheers
<br><br>
Neil Archibald<br>
- /dev/IT -