Jump to content

voting help


rchandran0023

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/59494-voting-help/
Share on other sites

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.