Re: can someone debug this vote.php script for me?
| From: | Phillip Bow | Date: | Mon, 30 Apr 2001 18:49:10 +0000 |
| Subject: | Re: can someone debug this vote.php script for me? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-50889@lists.php.net to get a copy of this message | ||
Its just a warning error. You can get rid of it by defining the variable,
or just change your error settings to not report warnings.
--
phill
""Joe Truong"" <joetruong@mediaone.net> wrote in message
news:9ce21h$s1n$1@toye.p.sourceforge.net...
> can some one debug this script for me... it say's "Warning: Undefined
> variable: total in PHP_poll.php on line 63"
>
> thanxz alot!!!
>
>
>
> <?php
>
> // En: Begin PHP Code
>
>
/***************************************************************************
> ***\
>
> * PHP Poll Version 1.0 *
>
> * Copyright 2000 Frederic TYNDIUK (FTLS) All Rights Reserved. *
>
> * E-Mail: tyndiuk@ftls.org Script License: GPL *
>
> * Created 02/28/2000 Last Modified 02/28/2000 *
>
> * Scripts Archive at: http://www.ftls.org/php/ *
>
>
****************************************************************************
> ***/
>
> // Necessary Variables:
>
> $RESULT_FILE_NAME = "poll_data.txt";
>
> // En: Absolute path and name to file contain poll data.
>
> $QUESTION = "How do you like this Script?";
>
> // En: Question Text.
>
> $ANSWER = array("Love it!", "Like it!", "Its okay..", "I
> dislike it", "I
> hate it..");
>
> // En: All answer.
>
> $IMG_DIR_URL = "./vote";
>
> // En: URL Directory of poll graphs.
>
> $REVOTE_TIME = 3600;
>
> // En: Time (second) after people can revote, use cookies.
>
> // End Necessary Variables section
>
>
/***************************************************************************
> ***/
>
> if (!isset($vote) && !isset($result)) {
>
> echo "<FORM METHOD=\"POST\">\n";
>
> echo "<TABLE CELLSPACING=0 CELLPADDING=2 BORDERCOLOR=#000000
> BORDER=1><TR><TD><TABLE WIDTH=\"100%\" BORDER=0>\n";
>
> echo "<TR><TH colspan=\"3\">$QUESTION</TH></TR>\n";
>
> while (list($key, $val) = each($ANSWER)) {
>
> echo "<TR><TD width=\"2%\"></TD><TD
> align=\"left\" width=\"96%\"><INPUT
> TYPE=\"radio\" NAME=\"answer\" VALUE=\"$key\">
> $val</TD><TD
> width=\"2%\"></TD></TR>\n";
>
> }
>
> echo "<TR><TD align=\"center\" colspan=\"3\"><INPUT
> TYPE=\"Submit\"
> NAME=\"vote\" VALUE=\" Vote \">\n";
>
> echo " <INPUT TYPE=\"Submit\" NAME=\"result\" VALUE=\" Result
> \"></TD></TR>\n";
>
> echo "</TABLE></TD></TR></TABLE></FORM>";
>
> } else {
>
> $file_array = file($RESULT_FILE_NAME); // or error("Can not open
> \$RESULT_FILE_NAME");
>
> // En: Save result
>
> 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);
>
> }
>
> // En: Display result
>
> while (list($key, $val) = each($file_array)) {
>
> $total += $val;
>
> }
>
> echo "<h2>PHP Poll vote results :</h2>";
>
> echo "<TABLE CELLSPACING=0 CELLPADDING=2 WIDTH=400 BORDERCOLOR=#000000
> BORDER=1>";
>
> echo
> "<tr><th>What</th><th>Percentage</th><th>Votes</th></tr>";
>
> while (list($key, $val) = each($ANSWER)) {
>
> $percent = $file_array[$key] * 100 / $total;
>
> $percent_int = floor($percent);
>
> $percent_float = number_format($percent, 1);
>
> $fp += $percent_float;
>
> echo "<tr><td> $ANSWER[$key] </td><td><img height=9
> src=\"$IMG_DIR_URL/vote_left.gif\">";
>
> echo "<img height=9 width=\"$percent_int\"
> src=\"$IMG_DIR_URL/vote_middle.gif\">";
>
> echo "<img height=9 src=\"$IMG_DIR_URL/vote_right.gif\"> $percent_float %
> </td>";
>
> echo
> "<td><CENTER>$file_array[$key]</CENTER></td></tr>";
>
> }
>
> echo "</TABLE><br>";
>
> }
>
> ?>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>