tbare Posted December 26, 2007 Share Posted December 26, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/83183-solved-trouble-w-posting-info-in-the-same-page/ Share on other sites More sharing options...
trq Posted December 26, 2007 Share Posted December 26, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/83183-solved-trouble-w-posting-info-in-the-same-page/#findComment-423126 Share on other sites More sharing options...
tbare Posted December 26, 2007 Author Share Posted December 26, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/83183-solved-trouble-w-posting-info-in-the-same-page/#findComment-423129 Share on other sites More sharing options...
kenrbnsn Posted December 26, 2007 Share Posted December 26, 2007 You need to have the "name" attribute in the "submit" button for $_POST['submit'] to be defined: <?php print "<INPUT type='submit' value='vote' name='submit'>\n"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/83183-solved-trouble-w-posting-info-in-the-same-page/#findComment-423130 Share on other sites More sharing options...
tbare Posted December 26, 2007 Author Share Posted December 26, 2007 heh... my name's mud... (not submit) :-D thanks! seems to be working now... a little more fine tuning, and it'll be ready to go live! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/83183-solved-trouble-w-posting-info-in-the-same-page/#findComment-423136 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.