Jump to content

[SOLVED] trouble w/ posting info in the same page...


tbare

Recommended Posts

having trouble w/ posting information in the same page... here's what i've got so far... (i include this file in another file...)

<?php

$numbers = file('ratings/' . $file . '.dat');
$count = "0";
$sum = "0";

foreach ($numbers as $line) {
list ($ip, $vote) = explode(':', $line);
$count++;
$sum = $sum+$vote;
}

$avg = $sum/$count;
$avg = round($avg,2);

$full = "<img src='ratings/images/all_star.png'> ";
$half = "<img src='ratings/images/half_star.png'> ";
$no = "<img src='ratings/images/no_star.png'> ";


//show stars here (bulky code removed)

print "rating: $avg with $count votes<br><br>\n\n";

//enable rating
if ( (!isset($_POST['submit'])) ) {
print "<form action='" . $_SERVER['PHP_SELF'] . "?file=" . $file . "&title=" . $title . "&cat=" . $cat . "' method='post'>\n";
print "<table>\n";
print "<tr><td><INPUT type='radio' name='rate' value='1'>   <br>1</td>\n";
print "<td><INPUT type='radio' name='rate' value='2'>   <br>2</td>\n";
print "<td><INPUT type='radio' name='rate' value='3'>   <br>3</td>\n";
print "<td><INPUT type='radio' name='rate' value='4'>   <br>4</td>\n";
print "<td><INPUT type='radio' name='rate' value='5'>   <br>5</td>\n";
print "<td><INPUT type='radio' name='rate' value='6'>   <br>6</td>\n";
print "<td><INPUT type='radio' name='rate' value='7'>   <br>7</td>\n";
print "<td><INPUT type='radio' name='rate' value='8'>   <br>8</td>\n";
print "<td><INPUT type='radio' name='rate' value='9'>   <br>9</td>\n";
print "<td><INPUT type='radio' name='rate' value='10'>   <br>10</td></tr>\n";
print "</table>\n";
print "<INPUT type='submit' value='vote'>\n";
print "</form>\n";
}
else  { 
$rate = isset ($_POST['rate']) ? $_POST['rate'] : 0;
$alreadyRated = false;
$totalRates = 0;
$totalPoints = 0;

$ip = getenv('REMOTE_ADDR');
$oldResults = file("ratings/" . $file . ".dat");
foreach ($oldResults as $value) {
$oneRate = explode(':',$value);
if ($ip == $oneRate[0]) $alreadyRated = true;	   
$totalRates++;
$totalPoints += $oneRate[1];
}
  if ((!$alreadyRated) && ($rate > 0)){            
    $f = fopen('ratings/' . $file . '.dat',"a+");         
    fwrite($f,$ip . ':' . $rate . "\n");
    fclose($f);
    $totalRates++;
    $totalPoints+=$rate;
} else {
    print "Sorry, only one vote per IP.";
}
}
?>

 

any ideas why it's not working?

In this line....

 

print "<form action='" . $_SERVER['PHP_SELF'] . "?file=" . $file . "&title=" . $title . "&cat=" . $cat . "' method='post'>\n";

 

you have a bunch of undefined variables.

 

You also use....

 

if ( (!isset($_POST['submit'])) ) {

 

Yet none of your form attributes are named submit.

 

Other than that, define what not working means. What is happening? What do you expect to happen?

sorry... $file, $title, and $cat are all defined on the page that this is included.. (basically, the url that this page is on is something like: 'http://www.domain.com/test.php?file=blah.flv&title=blah2&cat=blah3') and the

if ( (!isset($_POST['submit'])) ) {

is defined:

 print "<INPUT type='submit' value='vote'>\n";

there... (unless i'm doing that wrong)...

 

and as far as 'not working', the page refreshes, but the data is not being written the file that it's supposed to be (ratings/$file.dat)... nothing happens at all...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.