SELECT * FROM $user_data_db_name WHERE USER_NAME='$form_values{'USER_NAME'}' isn't interpolating the values the way you thing it is: you're searching for the record where the username is literally $form_values...

Instead of this, try

$sqlCount = "SELECT COUNT(*) FROM $user_data_db_name WHERE USER_NAME=? +"; $sth = $dbh->prepare($sqlCount) || die "Cannot prepare: " . $dbh->errs +tr(); $sth->execute($form_values{'USER_NAME'}) or die "Cannot execute: " . $ +sth->errstr(); my $occurences = $sth->fetchrow_arrayref->[0];

And find out why bind variables are your friend

As an aside, do you really want the table name to be a variable. Could be messy if it gets the wrong value into it.

--
Tommy
Too stupid to live.
Too stubborn to die.


In reply to Re: DBI : select count by tommyw
in thread DBI : select count by punchcard_bob

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.