I have now spent 2 hours looking over this code and testing different things and can not figure out what is wrong. Testing is showing that $OldRatting[0] is getting filled with the column name from the SQL command here:
$sth = $dbh -> prepare (qq~select ? from FanRatings where Title =
+?~) or die $DBI::errstr;
$sth -> execute ($rating, $filename) or die $DBI::errstr;
@OldRating = $sth -> fetchrow_array;
This is the full code I use. Can anyone tell me what I am doing wrong?
#!/user/perl
use CGI q~:standard~;
use CGI::Cookie;
use CGI::Carp qw(fatalsToBrowser);
use strict;
use DBI;
my ($dbh, $sth, $filename, $rating, @current, @VotedOn, %cookies, $Can
+Vote, $value, $c, @OldRating, $result);
$filename = param('name');
$rating = param('rating');
%cookies = fetch CGI::Cookie;
$CanVote = 1;
if (exists($cookies{'FFInfoVotedOn'})) {
@VotedOn = $cookies{'FFInfoVotedOn'} -> value;
foreach $value (@VotedOn) {
if ($value eq $filename) {
$CanVote = 0;
}
}
}
$dbh = DBI -> connect ('dbi:ODBC:', '', '') or die $DBI::errstr;
if ($CanVote) {
$result = 1;
$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~select ? from FanRatings where Title =
+?~) or die $DBI::errstr;
$sth -> execute ($rating, $filename) or die $DBI::errstr;
@OldRating = $sth -> fetchrow_array;
$OldRating[0]++;
$sth = $dbh -> prepare (qq~update FanRatings set ? = ? where Title
+ = ?~) or die $DBI::errstr;
$sth -> execute ($rating, $OldRating[0], $filename) or die $DBI::e
+rrstr;
@VotedOn = (@VotedOn, $filename);
$c = new CGI::Cookie(-name => 'FFInfoVotedOn',
-value => "@VotedOn",
-expires => '+10Y',
);
}
$dbh -> disconnect;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.