<?
$gid = $_GET['id'];
include ("config.php");
$allowed_rates = array('1', '2', '3', '4', '5');
if (isset($_GET['rate']) && in_array($_GET['rate'], $allowed_rates)) {
$rategame = 'illegal';
} else {
$rategame = $_GET['rate'];
}
$sql = mysql_fetch_array(mysql_query("SELECT * FROM games WHERE id = $gid"));
if (empty($sql[rate]) || $sql[rate] == '0') {
$rate = '0';
$ratenr = '1';
}
else {
$rate = $sql[rate];
$ratenr = $sql[ratenr];
}
if (empty($sql[ratem]) || $sql[ratem] == '0') {
$ratem = '0';
$ratemnr = '1';
}
else {
$ratem = $sql[ratem];
$ratemnr = $sql[ratemnr];
}
if (empty($sql[ratey]) || $sql[ratey] == '0') {
$ratey = '0';
$rateynr = '1';
}
else {
$ratey = $sql[ratey];
$rateynr = $sql[rateynr];
}
if ($rategame != 'illegal'){
$avg = $rate / $ratenr;
$avg2 = number_format($avg,2);
$ratewidth = $sql[rateavg] * 14;
$avgm = $ratem / $ratemnr;
$avgm2 = number_format($avgm,2);
$ratemwidth = $sql[ratemavg] * 14;
$avgy = $ratey / $rateynr;
$avgy2 = number_format($avgy,2);
$rateywidth = $sql[rateyavg] * 14;
}
if ($rategame != 'illegal' && isset($_GET["rate"]) && empty($_COOKIE["s$gid"])){
setcookie("s$gid", "$rategame", time()+604800);
include ("config.php");
mysql_query("UPDATE games SET ratenr = ratenr+1, rate = rate+$rategame, ratemnr = ratemnr+1, ratem = ratem+$rategame,
rateynr = rateynr+1, ratey = ratey+$rategame WHERE id = $gid") or die(mysql_error());
}
if (empty($rategame) && empty($_COOKIE['s$gid'])) {
$showrater = "<span class='rate'>
<span class='current-rating' style='width: $ratewidth px'> </span>
<span><a href='game.php?id=$gid&rate=1' title='Rate it 1' class='1'>1</a></span>
<span><a href='game.php?id=$gid&rate=2' title='Rate it 2' class='2'>2</a></span>
<span><a href='game.php?id=$gid&rate=3' title='Rate it 3' class='3'>3</a></span>
<span><a href='game.php?id=$gid&rate=4' title='Rate it 4' class='4'>4</a></span>
<span><a href='game.php?id=$gid&rate=5' title='Rate it 5' class='5'>5</a></span>
</span>";
}
if (isset($_COOKIE["s$gid"])){
$showrater = "<span class='rate'>
<span class='current-rating' style='width: $ratewidth px' title='Current rating: $avg2'> </span>
</span>";
}
mysql_query("UPDATE games SET rateavg = '$avg2', ratemavg = '$avgm2', rateyavg = '$avgy2' WHERE id = '$gid'") or
die(mysql_error());
?>
Jeg ved ikke hvad der er galt. Den tilføjer ingen hits i tabellen når man prøver at "rate", og der er ingen fejlmeddelelser... her er siden:
http://inheaven.awardspace.com/game.php?id=6