in reply to DBI : select count

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.

Replies are listed 'Best First'.
Re (2): DBI : select count
by VSarkiss (Monsignor) on May 09, 2002 at 17:10 UTC

    you're searching for the record where the username is literally $form_values...
    Um, no. The outermost quotes are double, so the variable is in fact being interpolated. Nonetheless, using placeholders as you've illustrated is a much better approach.

      Chris - spot on for the placement of finish()! Exactly the sort of fault that comes from staring at code too long - didn't even see it. Thanks.

      Tommy - thanks, but like VSarkiss says above, the quotes make it scope the hash and generates the query properly. But you guys are right about the usefulness of placeholders.