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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |