The following works.
#!/usr/bin/perl
use CGI;
use DBI;
use strict;
my $q=new CGI;
my $id=$q->param('vote');
my $dbh=DBI->connect(
'DBI:mysql:database:dbserver:3306',
'username',
'password',
{ AutoCommit => 1
}
);
my $sql_fmt="UPDATE contest SET VOTES=VOTES+1 WHERE ID='%d'";
my $sql=sprintf($sql_fmt, $id);
$dbh->do($sql);
my $sth=$dbh->prepare("SELECT * FROM contest");
$sth->execute();
my $content="Content-type: text/html\n\n";
$content.="<html>\n<head>\n<title>Susitna Linux Users Group</title>\n</head>\n<body>\n";
$content.="<center>Voting Results</center>\n";
$content.="<br><br>\n";
while (my @row = $sth->fetchrow_array()) {
$content .= "file: $row[1]<br>votes: $row[2]<br><br>\n";
}
$content.="</body>\n</html>\n";
print $content;
exit;
Of course, there's nothing saying the person can't sit there and repeatedly hit "submit", "back", "submit", "back"... and rack up piles of votes. |