$sqlCount = "SELECT COUNT(*) FROM $user_data_db_name WHERE USER_NAME='$form_values{'USER_NAME'}'"; $sth = $dbh->prepare($sqlCount) || die "Cannot prepare: " . $dbh->errstr(); $sth->execute() or die "Cannot execute: " . $sth->errstr(); my $occurences = $sth->fetchrow_arrayref->[0]; #### $sqlCount = "SELECT * FROM $user_data_db_name WHERE USER_NAME='$form_values{'USER_NAME'}'"; $sth = $dbh->prepare($sqlCount) || die "Cannot prepare: " . $dbh->errstr(); $sth->execute() or die "Cannot execute: " . $sth->errstr(); $sth->finish(); $ocurrences = 0; while (@data = $sth->fetchrow_array()) { $ocurrences++; }