Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/10/2006, 10:03
Borjimante
Invitado
 
Mensajes: n/a
Puntos:
Problema encuesta

tengo un problema con una encuesta y esque me da los siguientes fallos:

Cita:
Warning: fopen(base.txt) [function.fopen]: failed to open stream: File exists in /home/anteraso/public_html/encuesta1/encuesta/enc_ver.php on line 21

Warning: fwrite(): supplied argument is not a valid stream resource in /home/anteraso/public_html/encuesta1/encuesta/enc_ver.php on line 22

Warning: fclose(): supplied argument is not a valid stream resource in /home/anteraso/public_html/encuesta1/encuesta/enc_ver.php on line 23
index.php:

Cita:
<?
include("config.php"); //incluimos el fichero config.php donde tenemos la configuración del script
if(!file_exists($file)) //si el txt no existe...
{
$fp=fopen($file,"w"); //creamos un txt por si no tá creado
fputs($fp,"0\n0\n0\n0"); //le ponemos las respuestas desde 0
fclose($fp); //cerramos el txt
}


?>
<form method=POST action="enc_ver.php">
<input type="radio" name="En" value="E1" checked><? echo $c1;?><br>
<input type="radio" name="En" value="E2"><? echo $c2;?><br>
<input type="radio" name="En" value="E3"><? echo $c3;?><br>
<input type="radio" name="En" value="E4"><? echo $c4;?><br>
<input type="submit" value="Votar" name="Bot">
</form>
<p>
config.php:

Cita:
<?
// CONFIGURACION DE LA ENCUESTA
$file="base.txt"; //nombre del txt en el que guardaremos los resultados

//Escribe tus respuestas para la encuesta
$c1="Me encanta"; //Encuesta nº 1
$c2="Esta bien"; //Encuesta nº 2
$c3="Puede mejorarse"; //Encuesta nº 3
$c4="No me gusta"; //Encuesta nº 4
?>
enc_ver.php:

Cita:
<?
include("config.php"); //incluimos el fichero config.php donde tenemos la configuración del script

$file2=file($file); //creamos el array con las lineas del archivo
$lineas=count($file2);//contamos los elementos del array, es decir el total de lineas
$n1=$file2[0]; //asignamos a la variable el nº de votos(la línea 1 del txt)
$n2=$file2[1]; //asignamos a la variable el nº de votos(la línea 2 del txt)
$n3=$file2[2]; //asignamos a la variable el nº de votos(la línea 3 del txt)
$n4=$file2[3]; //asignamos a la variable el nº de votos(la línea 4 del txt)


if($En=="E1") //si la respuesta es la opción 1...
{$nn1=intval($n1)+1;}else{$nn1=intval($n1);} //entonces sumamos uno a $nn1, si no, se keda igual
if($En=="E2") //si la respuesta es la opción ...
{$nn2=intval($n2)+1;}else{$nn2=intval($n2);} //entonces sumamos uno a $nn2, si no, se keda igual
if($En=="E3") //si la respuesta es la opción 3...
{$nn3=intval($n3)+1;}else{$nn3=intval($n3);} //entonces sumamos uno a $nn3, si no, se keda igual
if($En=="E4") //si la respuesta es la opción 4...
{$nn4=intval($n4)+1;}else{$nn4=intval($n4);} //entonces sumamos uno a $nn4, si no, se keda igual

$fp=fopen($file,"x"); //abrimos de nuevo el txt borrándolo todo
fwrite($fp,"n$nn1\n$nn2\n$nn3\n$nn4"); //escribimos en el txt los votos.. en su respectiva línea. NOTA: \n <- cambia de línea ;)
fclose($fp); //cerramos el txt

$ntotal=$nn1+$nn2+$nn3+$nn4; //contamos el nº total de votos

?>

<table border=0 cellpadding=0 cellspacing=0 width=188>
<tr>
<td colspan=3 width=186><strong><font face=Arial>Resultados Encuesta</font></strong></td>
</tr>
<tr>
<td width=46><font face=Arial><? echo $c1;?></font></td>
<td width=101><table border=0 cellpadding=0 cellspacing=1 width=100
bgcolor="#000080">
<tr>
<td><table border=0 cellpadding=0 cellspacing=0 width=<? echo $nn1*100/$ntotal;?> bgcolor=#FFFFFF
height=5>
<tr>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td width=37><p align=center><font face=Arial size=2><? echo $nn1;?></font></td>
</tr>
<tr>
<td width=46><font face=Arial><? echo $c2;?></font></td>
<td width=101><table border=0 cellpadding=0 cellspacing=1 width=100%
bgcolor=#000080>
<tr>
<td width=100%><table border=0 cellpadding=0 cellspacing=0 width=<? echo $nn2*100/$ntotal;?>
bgcolor=#FFFFFF height=5>
<tr>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td width=37><p align=center><font face=Arial size=2><? echo $nn2;?></font></td>
</tr>
<tr>
<td width=46><font face=Arial><? echo $c3;?></font></td>
<td width=101><table border=0 cellpadding=0 cellspacing=1 width=100%
bgcolor=#000080>
<tr>
<td width=100%><table border=0 cellpadding=0 cellspacing=0 width=<? echo $nn3*100/$ntotal;?>
bgcolor=#FFFFFF height=5>
<tr>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td width=37><p align=center><font face=Arial size=2><? echo $nn3;?></font></td>
</tr>
<tr>
<td width=46><font face=Arial><? echo $c4;?></font></td>
<td width=101><table border=0 cellpadding=0 cellspacing=1 width=100%
bgcolor=#000080>
<tr>
<td width=100%><table border=0 cellpadding=0 cellspacing=0 width=<? echo $nn4*100/$ntotal;?>
bgcolor=#FFFFFF height=5>
<tr>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td width=37><p align=center><font face=Arial size=2><? echo $nn4;?></font></td>
</tr>
<tr>
<td width=184 colspan=3><font face=Arial>Total encuesta: </font><font
color=#004080 face=Arial size=2><strong><? echo $ntotal;?></strong></font></td>
</tr>
</table>

<br>
<a href="file:///C|/Documents%20and%20Settings/AVILA/Escritorio/encuesta1/encuesta/index.php">Volver</a>
Donde esta el fallo? ayuda por favor

PD: el archibo base.txt esta subido