Hi, I installed this php poll on my site which I downloaded from some free PHP script site, I lost the URL... but anyway, I installed the poll on my site and it seems to be working okay, but I -know- something is wrong.
Here is my page, (still in progress) and please if you want to help me, ignore the broken links and all the pictures and simple go down to the poll at the bottom.
http://www.mzanime.com/av/
The php_poll is designed to store the poll results (as simple numbers) in a text file. And I believe it uses cookies, to do this. However when you make a vote, it seems to save the vote, but it doesn't.
TEST: Make a vote. Then it'll display that vote on the results. Now, quit your browser, reopen it and return to the page, this time click "See Results" button and where did your vote go????
It is not saving it, and it seems that the cookie thing isn't working properly either. Here is my PHP code:
<?php
// Begin PHP Code
/******************************************************************************\
* PHP Poll Version 1.0 *
* Copyright 2000 Frederic TYNDIUK (FTLS) All Rights Reserved. *
* E-Mail: [email]tyndiuk@ftls.org[/email] Script License: GPL *
* Created 02/28/2000 Last Modified 02/28/2000 *
* Scripts Archive at: [url]http://www.ftls.org/php/[/url] *
*******************************************************************************/
// Necessary Variables:
$RESULT_FILE_NAME = "http://www.mzanime.com/poll_data.txt";
// Absolute path and name to file containing poll data.
$QUESTION = "Which movie did you enjoy best?";
// Question Text.
$ANSWER = array("Onegai Teacher", "Snow Fairy Sugar", "Mahoromatic Maiden", "Hanaukyo Maid-Tai", "Kokoro Library");
// All answers.
$IMG_DIR_URL = "http://www.mzanime.com/vote";
// URL Directory of poll graphics.
$REVOTE_TIME = 3600;
// Time (second) after people can revote, uses cookies.
// End Necessary Variables section
/******************************************************************************/
if (! $vote && ! $result) {
echo "<FORM METHOD=\"POST\">\n";
echo "<TABLE CELLSPACING=0 WIDTH=80% BORDER=0 BGCOLOR=\"#006699\"><TR><TD><TABLE WIDTH=\"100%\" CELLSPACING=0 BORDER=0>\n";
echo "<TR><TH BGCOLOR=\"#EEF3F9\" style=\"border-bottom:solid 1px #666666\">$QUESTION</TH></TR>\n";
while (list($key, $val) = each($ANSWER)) {
echo "<TR><TD BGCOLOR=\"#ffffff\" style=\"border-bottom:solid 1px #E8E8E8\"><INPUT TYPE=\"radio\" NAME=\"answer\" VALUE=\"$key\"> $val</TD></TR>\n";
}
echo "<TR><TD BGCOLOR=\"#ffffff\" style=\"border-bottom:solid 1px #E8E8E8\"><INPUT TYPE=\"Submit\" NAME=\"vote\" VALUE=\" Vote \" style=\"background-color: #0099CC; font-family: Arial; font-size: 3mm; font-weight: bold; color: #FFFFFF\"> <INPUT TYPE=\"Submit\" NAME=\"result\" VALUE=\" See Results \" style=\"background-color: #0099CC; font-family: Arial; font-size: 3mm; font-weight: bold; color: #FFFFFF\"></TD></TR>\n";
echo "</TABLE></TD></TR></TABLE></FORM>";
} else {
$file_array = file($RESULT_FILE_NAME); // or error("Can not open \$RESULT_FILE_NAME");
// Save results
if ($answer < count($ANSWER) && $vote) {
if (count($file_array) < count($ANSWER)) {
$file_array = array("0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n");
}
$old_answer = $file_array[$answer];
$old_answer = preg_replace("/\n\r*/", "", $old_answer);
$file_array[$answer] = ($old_answer + 1)."\n";
$file = join('', $file_array);
$fp = fopen("$RESULT_FILE_NAME", "w"); //or error("Can not write \$RESULT_FILE_NAME");
flock($fp, 1);
fputs($fp, $file);
flock($fp, 3);
fclose($fp);
echo "rate saved";
}
// Display results
while (list($key, $val) = each($file_array)) {
$total += $val;
}
echo "<h2>Anime Movie Poll vote results :</h2>";
echo "<TABLE CELLSPACING=0 WIDTH=80% BORDER=0 BGCOLOR=\"#006699\"><TR><TD><TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=1 BORDER=0>";
echo "<tr><td BGCOLOR=\"#EEF3F9\" style=\"border-bottom:solid 1px #666666\"><b> What Movie</b></td><td BGCOLOR=\"#EEF3F9\" style=\"border-bottom:solid 1px #666666\"><b>Percentage</b></td><td BGCOLOR=\"#EEF3F9\" style=\"border-bottom:solid 1px #666666\"><b>Votes</b></td></tr>";
while (list($key, $val) = each($ANSWER)) {
$percent = $file_array[$key] * 100 / $total;
$percent_int = floor($percent);
$percent_float = number_format($percent, 1);
$tp += $percent_float;
echo "<tr><td bgcolor=\"#ffffff\" style=\"border-bottom:solid 1px #E8E8E8; border-right:solid 1px #E8E8E8\"> $ANSWER[$key] </td><td bgcolor=\"#ffffff\" style=\"border-bottom:solid 1px #E8E8E8; border-right:solid 1px #E8E8E8\"><img height=9 src=\"$IMG_DIR_URL/vote_left.gif\"><img height=9 width=\"$percent_int\" src=\"$IMG_DIR_URL/vote_middle.gif\"><img height=9 src=\"$IMG_DIR_URL/vote_right.gif\"> $percent_float % </td><td bgcolor=\"#ffffff\" style=\"border-bottom:solid 1px #E8E8E8\">$file_array[$key]</td></tr>";
}
echo "</TABLE></td></tr></table><br>";
}
?>
I have also attached my poll_data.txt file, as you can see it is mostly just numbers. Any help would be MUCH appreciated.