in reply to Explain SQL statement

Just a comment with your SQL statement, you may or may not know this already. It is a good practice to avoid interpolating variables in your SQL statement, use placeholders (?) instead. This will prevent foreseeable SQL injection attacks.

So instead of doing something like:
my $sql = "SELECT * FROM tbl_admin WHERE day = '$d' ...."; my $sth = $dbh->prepare($sql); $dbh->exec();
Do this instead:
my $sql = "SELECT * FROM tbl_admin WHERE day = ? ...."; # note the ? (question mark) placeholder my $sth = $dbh->prepare($sql); $dbh->exec($d);