Tried adding an if statment to check value but am still erroring out with "Can't call method "value" on an undefined value at vote.pl line 14." line 14 is the if statment.
#!/user/perl
use CGI q~:standard~;
use CGI::Cookie;
use CGI::Carp qw(fatalsToBrowser);
use strict;
use DBI;
print "Content-type: text/html\n\n";
my ($dbh, $sth, $filename, $rating, @current, @VotedOn, %cookies, $Can
+Vote, $value, $c);
$filename = param('name');
$rating = param('rating');
%cookies = fetch CGI::Cookie;
$CanVote = 1;
@VotedOn = '';
if ($cookies{'FFInfoVotedOn'} -> value) {
@VotedOn = $cookies{'FFInfoVotedOn'} -> value;
foreach $value (@VotedOn) {
if ($value eq $filename) {
$CanVote = 0;
}
}
}
if ($CanVote) {
$dbh = DBI -> connect ('dbi:ODBC:FFmisc', '', '') or die $DBI::err
+str;
$sth = $dbh -> prepare (qq~select One, Two, Three, Four, Five from
+ FanRatings where Title = ?~) or die $DBI::errstr;
$sth -> execute ($filename) or die $DBI::errstr;
@current = $sth -> fetchrow_array;
if (!defined $current[0]) {
$sth -> $dbh -> prepare (qq~insert FanRatings (Title, One, Two
+, Three, Four, Five) values (?, 0, 0, 0, 0, 0)~) or die $DBI::errstr;
$sth -> execute ($filename) or die $DBI::errstr;
}
$sth = $dbh -> prepare (qq~update FanRatings set ? = ? + 1 where T
+itle = ?~) or die $DBI::errstr;
$sth -> execute ($rating, $rating, $filename) or die $DBI::errstr;
@VotedOn = (@VotedOn, $filename);
$c = new CGI::Cookie(-name => 'FFInfoVotedOn',
-value => @VotedOn,
-expires => '+10Y',
);
print header(-cookie => $c);
print qq~Thank you for rating this fan creation.~;
} else {
print qq~I am sorry but you have alrady rated this fan creation.~;
}
print qq~<br />You will automaticly be taken back to the page you came
+ from in 5 seconds.~;
|