I need some help... I have a rating/ vote thing on my download database, where you can rate the file out of 5. Whenever you rate a file, instead of showing the average rate, it shows the last rate of the file. Please help...
This is my download.php file, where the file is sent and you can rate the file...
<?php
// connect to mysql database
$db = mysql_connect("localhost","jointops_site","password");
mysql_select_db (jointops_site);
// Ask the database for the information from the dl's table
$query = "UPDATE downloads SET downloads = downloads + 1 WHERE id='" . $_GET['id'] . "'";
$result = mysql_query($query) or die(mysql_error());
// send the file (hopefully you knows how to do this...)
echo "<a href= '$rows[9]'>Download Now...</a><br><br><br>RATE THE FILE!!!<br><br>";
echo "<form method=\"POST\" action=\"rate.php?id=$rows[0]\">
<input type=\"hidden\" name=\"id\" value=\"$id\">
<input type=\"radio\" value=\"5\" checked name=\"rating\">5/5
<input type=\"radio\" name=\"rating\" value=\"4\">4/5
<input type=\"radio\" name=\"rating\" value=\"3\">3/5
<input type=\"radio\" name=\"rating\" value=\"2\">2/5
<input type=\"radio\" name=\"rating\" value=\"1\">1/5
<input type=\"submit\" value=\"Submit\" name=\"B1\">
</form>";
?>
Here is "Rate.php"
<?php
//now let's proccess the rating and insert into the database
if (empty($rating) || !is_numeric($rating))
echo "Go back and select a rating";
else
{
$db=mysql_connect("localhost", "jointops_site", "password") or die(mysql_error());
mysql_select_db("jointops_site", $db) or die(mysql_error());
$query = "SELECT votes, rating FROM downloads WHERE id='$id'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_row($result) or die('no such file');
$row[0] += 1;
$row[1] += $rating;
$secondquery = 'UPDATE downloads SET votes='.$row[1].',votes='.$row[0].' WHERE id='.$id;
$secondresult = mysql_query($secondquery, $db) or die(mysql_error());
$average=$row[1]/$row[0];
$thirdquery = 'UPDATE downloads SET rating='.$rating.' WHERE id='.$id;
$thirdresult = mysql_query($thirdquery, $db) or die(mysql_error());
echo "Thank you for rating this file. Thanks to you, the overall rating for this file is now $rating";
}
?>
http://www.joint-ops.net/files ...