Let's ignore for a moment the strange use of "select *" when what you really want is two specific columns and the seemingly unnecessary usage of grep...
In that world, you could do something along the lines of:
#!C:\strawberry\perl\bin\perl.exe
use dbi;
use strict;
use warnings;
my $usernameentered = "user89";
my $passwordentered = "password12";
my $dbh = DBI->connect('dbi:mysql:Database','username','password')
or die "Connection Error: $DBI::errstr\n";
my $sql = "select * from usertable";
my $sth = $dbh->prepare($sql);
$sth->execute
or die "SQL Error: $DBI::errstr\n";
while (my @row = $sth->fetchrow_array) {
my @username= grep /$usernameentered/, @row;
print "@username\n";
my @password= grep /$passwordentered/, @row;
print "@password\n";
#if (@username !=$usernameentered)
if ($username[0] ne $usernameentered)#??which index??
{
print "incorrect username entered **$username[0]**\n";
}
#if (@password !=$passwordentered)
if ($password[0] ne $passwordentered)#??which index??
{
print "incorrect password entered $password[0]**\n";
}
}
Now, back in the real world, why not just let the database do the work for you?
#!C:\strawberry\perl\bin\perl.exe
use dbi;
use strict;
use warnings;
my $usernameentered = "user89";
my $passwordentered = "password12";
my $dbh = DBI->connect('dbi:mysql:Database','username','password')
or die "Connection Error: $DBI::errstr\n";
my $sql = "select user from usertable where user = ? and pwd = ?";
my $sth = $dbh->prepare($sql)
or die "SQL Error: $DBI::errstr\n";
$sth->execute($usernameentered, $passwordentered)
or die "SQL Error: $DBI::errstr\n";
while (my @row = $sth->fetchrow_array) {
#do whatever you want with this user
}
The last thing that jumps out is that you are evidently storing pwds in the database in clear text. That's a no-no, unless you really don't care about the passwords, in which case why use them in the first place? But, perhaps this is not your decision. If it is, you should use one of the many one-way hash modules on cpan to create a hash of the password and then store THAT, rather than storing the password itself.