pasa al resultado.php
pero cuando cargo de nuevo encuesta.php
me da el siguiente error
Has pasado por pagina1.php
Warning: Cannot modify header information - headers already sent by (output started at /home/ju000393/public_html/zzz/encuesta.php:6) in /home/ju000393/public_html/zzz/encuesta.php on line 7
encuesta.php
Código PHP:
<?php
//Retomamos la sesión
session_start();
//Chequeamos si la variable de sesión existe
if($_SESSION[id]) {
echo 'Has pasado por pagina1.php';
header("Location: resultado.php");
}
//cargo el numero de respuestas de un fichero de texto
$f=fopen("encuesta.txt","r");
$todas=fread($f,filesize("encuesta.txt"));
$respuestas=explode(",",$todas);
fclose($f);
if ($respuesta) {
//incremento la respuesta y la guardo en el fichero
$respuestas[$respuesta-1]++;
$f=fopen("encuesta.txt","w");
$todas=$respuestas[0].",".$respuestas[1].",".$respuestas[2].",".$respuestas[3];
fwrite($f,$todas,strlen($todas));
fclose($f);
}
?>
<body bgcolor="#394984" text="#FAFFFF" topmargin="10" leftmargin="10">
<form name="encuesta" action="resultado.php" method="post""><FONT style="FONT-SIZE: 9pt"><b>
Que Preferis:</font></b><br><FONT style="FONT-SIZE: 7pt" color=#ffffff><BR>
<input type=radio name="respuesta" Value="1"> Dance <br>
<input type=radio name="respuesta" Value="2"> Latin <br>
<input type=radio name="respuesta" Value="3"> Pop <br>
<input type=radio name="respuesta" Value="4"> Rock <br><BR>
<input type="submit" value="Votar">
</form>
resultado php
Código PHP:
<?php
//Inicializamos la sesión para comenzar
session_start();
//Registramos dos variables de sesión
$_SESSION[id] = session_id();
//cargo el numero de respuestas de un fichero de texto
$f=fopen("encuesta.txt","r");
$todas=fread($f,filesize("encuesta.txt"));
$respuestas=explode(",",$todas);
fclose($f);
if ($respuesta) {
//incremento la respuesta y la guardo en el fichero
$respuestas[$respuesta-1]++;
$f=fopen("encuesta.txt","w");
$todas=$respuestas[0].",".$respuestas[1].",".$respuestas[2].",".$respuestas[3];
fwrite($f,$todas,strlen($todas));
fclose($f);
}
$total=$respuestas[0]+$respuestas[1]+$respuestas[2]+$respuestas[3];
if($total==0) {
$porcentaje[0]=0;
$porcentaje[1]=0;
$porcentaje[2]=0;
$porcentaje[3]=0;
} else {
$porcentaje[0]=sprintf("%1.2f",(($respuestas[0]/$total)*100));
$porcentaje[1]=sprintf("%1.2f",(($respuestas[1]/$total)*100));
$porcentaje[2]=sprintf("%1.2f",(($respuestas[2]/$total)*100));
$porcentaje[3]=sprintf("%1.2f",(($respuestas[3]/$total)*100));
}
?>
<body bgcolor="#394984" text="#FFFFFF" topmargin="10" leftmargin="10">
<table border="0"><FONT style="FONT-SIZE: 9pt" color=#ffffff><b>
<tr>
<td colspan="3" align="center"><FONT style="FONT-SIZE: 9pt"><b>
Que Preferis<br></font></b><br>
</td>
</tr>
<tr>
<td align="left">
<FONT style="FONT-SIZE: 9pt" color=#ffffff><b>
Dance
</font></b>
</td>
<td align="left">
<img src="red.png" height="15" width="<?php echo "$porcentaje[0]"; ?>">
</td>
<td>
<FONT style="FONT-SIZE: 9pt" color=#ffffff><b>
<?php echo "$porcentaje[0]%"; ?>
</font></b>
</td>
</tr>
<tr>
<td align="left">
<FONT style="FONT-SIZE: 9pt" color=#ffffff><b>
Latin
</font></b>
</td>
<td align="left">
<img src="blue.png" height="15" width="<?php echo "$porcentaje[1]"; ?>">
</td>
<td>
<FONT style="FONT-SIZE: 9pt" color=#ffffff><b>
<?php echo "$porcentaje[1]%"; ?>
</font></b>
</td>
</tr>
<tr>
<td align="left">
<FONT style="FONT-SIZE: 9pt" color=#ffffff><b>
Pop
</font></b>
</td>
<td align="left">
<img src="yellow.png" height="15" width="<?php echo "$porcentaje[2]"; ?>">
</td>
<td>
<FONT style="FONT-SIZE: 9pt" color=#ffffff><b>
<?php echo "$porcentaje[2]%"; ?>
</font></b>
</td>
</tr>
<tr>
<td align="left">
<FONT style="FONT-SIZE: 9pt" color=#ffffff><b>
Rock
</font></b>
</td>
<td align="left">
<img src="green1.png" height="15" width="<?php echo "$porcentaje[3]"; ?>">
</td>
<td>
<FONT style="FONT-SIZE: 9pt" color=#ffffff><b>
<?php echo "$porcentaje[3]%"; ?>
</font></b>
</td>
</tr>
</table>
<br><br>
alguien puede ayudarme y decirme que estoy haciendo mallll???
gracias