Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Script per sondaggio non funziona...

    Buon pomeriggio, ho questo problema.Vorrei sapere per favore come mai, questo script, preso qui su Html.it, per il sondaggio, non mi funziona.
    In pratica non riesce ne a scrivere ne a leggere, nel .txt.
    Questo è lo script:
    codice:
    <?
    $RESULT_FILE_NAME = "php_poll/poll_data.txt";
    	// En: Absolute path and name to file contain poll data.
    	// Fr: Chemin absolu (complet) et Nom du fichier contenant les donne.
    
    $QUESTION = "How do you like this Script?";
    	// En: Question Text.
    	// Fr: Texte de la question.
    $ANSWER = array("Love it!", "Like it!", "Its okay..", "I dislike it", "I hate it..");
    	// En: All answer.
    	// Fr: Reponses possibles
    
    $IMG_DIR_URL = "./vote";
    	// En: URL Directory of poll graphs.
    	// Fr: URL du repertoire des images.
    
    $REVOTE_TIME = 3600;
    	// En: Time (second) after people can revote, use cookies.
    	// Fr: Temps en second apres lequel une personne peut revoter.
    
    // End  Necessary Variables section
    /******************************************************************************/
    
    $vote = $_POST['vote'];
    $result = $_POST['result'];
    $answer = $_POST['answer'];
    
    if (! $vote && ! $result) {
    	echo "<FORM METHOD=\"POST\">\n";
    	echo "	<TABLE WIDTH=100% BORDER=1>
    				<TR>
    					<TD>
    						<TABLE WIDTH=\"100%\" BORDER=0>\n";
    					echo "	<TR>
    								<TH>$QUESTION</TH>
    							</TR>\n";
    			while (list($key, $val) = each($ANSWER)) {
    					echo "	<TR>
    								<TD align=\"center\">
    									<INPUT TYPE=\"radio\" NAME=\"answer\" VALUE=\"$key\"> $val $key
    								</TD>
    							</TR>\n";
    			} 
    					echo "	<TR>
    								<TD align=\"center\">
    									<INPUT TYPE=\"Submit\" NAME=\"vote\" VALUE=\" Vote \">
    								</TD>
    							</TR>\n";
    					echo "	<TR>
    								<TD align=\"center\">
    									<INPUT TYPE=\"Submit\" NAME=\"result\" VALUE=\" See 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
    	// Fr: Enregistre le resultat
    	if ($answer < count($ANSWER) && $vote) {
    		if (count($file_array) < count($ANSWER))  {
    			$file_array = array("0\n", "0\n", "0\n", "0\n", "0\n");
    		}
    		$old_answer = $file_array[$answer];
    		echo "1: " . $old_answer;
    		$old_answer = preg_replace("/\n\r*/", "", $old_answer);
    		echo "2: " . $old_answer;
    		$file_array[$answer] = ($old_answer + 1)."\n";
    		echo "3: " . $file_array[$answer];
    		$file = join('', $file_array);
    		echo "4: " . $file;
    		$fp = fopen($RESULT_FILE_NAME, "w"); //or error("Can not write \$RESULT_FILE_NAME");
    		flock($fp, 1);
    		fputs($fp, $file); //scrive nel file                                                    
    		flock($fp, 3);
    		fclose($fp);
    		echo "rate saved";
    	}
    
    	// En: Display result
    	// Fr: Affiche le resultat
    	while (list($key, $val) = each($file_array)) {
    		$total += $val;
    	}
    
    	echo "<h2>PHP Poll vote results :</h2>";
    	echo "<TABLE CELLSPACING=2 CELLPADDING=1 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);
    		$tp += $percent_float;
    		echo "<tr><td> $ANSWER[$key] </td><td><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>$file_array[$key]</td></tr>";
    	}
    
    	echo "</TABLE>
    ";
    }
    
    ?>
    Scusate se ho postato tutto il codice, ma..non sapevo come fare..!!
    Attendo delucidazioni..
    Grazie 1000

  2. #2
    ragazzi, potete dirmi per favore dov'è l'errore?
    Sto diventando matto, c'a faz chiù...
    vi ringrazio, come sempre...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.