rchandran0023 Posted July 11, 2007 Share Posted July 11, 2007 i have dloaded a nice little simple voting app but cant get it to work. It will not display the stats when the "view results" button is clicked. Iv tried to put "$results = $_POST['results'];" in different places in the code but the best i can get is it will pop up with the stats but they wont be correct. ??? Any help would be much appreciated and im sure it will help others as well. I am an official phpfreaks donating member. ......................................................................... <code> <? // $results = $_POST['results']; $filename = "poll.txt"; $fl=fopen($filename,'r'); $name = fgets($fl, 4096); $options[0] = fgets($fl, 5); $temp = $options[0]; while ($temp) { $theoptions[$temp] = fgets($fl, 4096); $temp = $temp - 1; } $temp = $options[0]; while ($temp) { $thevalues[$temp] = fgets($fl, 4096); $temp = $temp - 1; } fclose($fl); if ($results) { echo "$name<br>"; $temp = $options[0]; while ($temp) { if ($thevalues[$temp] == 0) { $percent = 0; } else { $tempnum = $options[0]; $total = 0; while ($tempnum) { $total += Trim($thevalues[$tempnum]); $tempnum = $tempnum - 1; } $percent = 100 * Trim($thevalues[$temp]) / $total; if (strlen($percent) > 4) { $percent = substr($percent, 0, 4); } } echo "$theoptions[$temp]: $percent% ($thevalues[$temp] votes)<br><br>"; $temp = $temp - 1; } } elseif ($vote) { echo "You voted for $theoptions[$optradio]<br>"; unlink($filename); $fl = fopen($filename, 'w'); fputs($fl, "$name"); fputs($fl, "$options[0]"); $temp = $options[0]; while ($temp) { fputs($fl, "$theoptions[$temp]"); $temp = $temp - 1; } $temp = $options[0]; while ($temp) { if ($temp == $optradio) { fputs($fl, "$thevalues[$temp]" + 1); fputs($fl, "\n"); $temp = $temp - 1; } else { fputs($fl, "$thevalues[$temp]"); $temp = $temp - 1; } } fclose($fl); } else { echo "$name<br>"; $temp = $options[0]; echo "<form method=\"post\" action=\"$PHP_SELF\">"; while ($temp) { echo "<input type=\"radio\" name=\"optradio\" value=\"$temp\"> $theoptions[$temp]<br>"; $temp = $temp - 1; } echo "<input type=\"submit\" name=\"vote\" value=\"Vote\">"; echo "<input type=\"submit\" name=\"results\" value=\"View Results\">"; } ?> </code> Quote Link to comment https://forums.phpfreaks.com/topic/59494-voting-help/ Share on other sites More sharing options...
wildteen88 Posted July 11, 2007 Share Posted July 11, 2007 That code requires register_globals. register_globals is now disabled by default as it can cause security exploits within your code. I'd say dump that script and look for script that does not replay on register_globals. Quote Link to comment https://forums.phpfreaks.com/topic/59494-voting-help/#findComment-295694 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.