koden:
<?php
$sid = $_GET['id'];
$rate = $_POST['rate'];
if (empty($rate)) {
$rate = $_COOKIE['s$sid'];
}
if (isset($_POST['rate']) || isset($_COOKIE['s$sid'])){
setcookie("s$sid", "$rate", time()+604800);
echo "<select>
<option value=''>You rated: $rate
</select>";
}
if (isset($_POST["rate"]) && empty($_COOKIE["s$sid"])){
include ("config.php");
mysql_query("UPDATE games SET rate = rate+1, ratenr = ratenr+$rate, ratem = ratem+1, ratemnr = ratemnr+$rate, ratey =
ratey+1, rateynr = rateynr+$rate WHERE id = '$sid'") or die(mysql_error());
}
if (empty($rate)) {
echo "<b>Rate game: </b><form method='post' action='$PHP_SELF'><select name='rate'>
<option value='5'>5
<option value='4'>4
<option value='3'>3
<option value='2'>2
<option value='1'>1
</select>
<input type='submit' value='Rate!'></form>";}
include ("config.php");
$result = mysql_query("SELECT * FROM games WHERE id = $sid") or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$avg = $row[rate] / $row[ratenr];
$avg2 = number_format($avg,2);
echo "
<br><b>Total rates:</b> ".$row[ratenr]."<br> <b>Average rating:</b> $avg2
";}
?>
siden:
http://inheaven.awardspace.com/rate.php?id=1 Problemet(erne):
når jeg prøver at "rate" sker der dette:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1og når man åbner siden så står der :
Warning: Division by zero in /home/www/inheaven.awardspace.com/rate.php on line 37 Jeg ved godt at det er fordi den bliver sat til at dividere med nul (da der ikke er noget i tabellen endnu), men hvordan forhindrer jeg denne fejlmeddelelse?
håber nogen vil hjælpe... på forhånd tak