Hi guys
I need some help. I am creating a rating script for my website and want multiple rating facility on one page. Below is the PHP I have come up with but it’s not working. The “filename” bit ($filename) I change each occurance of the script so that, in theory, the results all store in different files. However, when rate is clicked on it saves the same thing to every result file - meaning visitors will only be able to vote once and then the same vote is added to everything. Any ideas?
<?php if ( (!isset($_POST['submit'])) ) { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="100%">
<tr><td>Your rating:</td><td><select name="rate">
<?php for ($i = 1; $i <= 10; $i++) { echo "<option value="$i">$i</option>"; } ?>
</select></td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Rate it!" name="submit"/></td></tr>
</table>
</form>
<?php } else {
$rate = isset ($_POST['rate']) ? $_POST['rate'] : 0;
$filename = "ratings";
$alreadyRated = false;
$totalRates = 0;
$totalPoints = 0;
$ip = getenv('REMOTE_ADDR');
$oldResults = file('results/'.$filename.'.txt');
foreach ($oldResults as $value) {
$oneRate = explode(':',$value);
if ($ip == $oneRate[0]) $alreadyRated = true;
$totalRates++;
$totalPoints += $oneRate[1];
}
if ((!$alreadyRated) && ($rate > 0)){
$f = fopen('results/'.$filename.".txt","a+");
fwrite($f,$ip.':'.$rate."n");
fclose($f);
$totalRates++;
$totalPoints+=$rate;
}
?>
"; for ($i=0;$i<round(($totalPoints/$totalRates),0);$i++){ echo "