Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi Monks,
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.
Here is the code i have written:
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; }
However this will always return 0 for all cases. When i remove  and $row[1] == $mid 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.

I have also tried the sql statement:  SELECT S_Email,MID FROM ML_Subscribers WHERE MID = '$mid' AND  S_Email = '$email' and then tested if  $row[0] is true.
None of these things worked so i am pretty stuck for ideas.
I'm sure it has to be something stupid i am over looking, i would appreciate any input.
Cheers

Neil Archibald
- /dev/IT -

In reply to SQL - Subroutine always returning true by devslashneil

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-23 11:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found