Foros del Web » Programando para Internet » PHP »

Pequeño fallo en una encuesta

Estas en el tema de Pequeño fallo en una encuesta en el foro de PHP en Foros del Web. Hola, tengo ya una encuesta casi preparada a base de esta aplicación: Fpoll v1.0 by PHPFront.com La e traducido y modificado a mi gusto, solo ...
  #1 (permalink)  
Antiguo 28/06/2007, 07:32
Borjimante
Invitado
 
Mensajes: n/a
Puntos:
Pequeño fallo en una encuesta

Hola, tengo ya una encuesta casi preparada a base de esta aplicación:

Fpoll v1.0 by PHPFront.com

La e traducido y modificado a mi gusto, solo queda un pequeño detalle y es que cuando voto en una encuesta registra el voto pero me da este fallo:

Cita:
Warning: Cannot modify header information - headers already sent by (output started at /home/anteraso/public_html/encuesta/index.php:10) in /home/anteraso/public_html/encuesta/Fpoll/poll.php on line 83
y cuando resfresco la encuesta ya no aparece el fallo y todo sale bien, el codigo de poll.php es este:

Código PHP:
<?php 

// Author: PHPFront.com © 2005
// License: Free (GPL)
//
// Version: 1.0
//
// Created: 8.12.2005 
//
// More information and downloads 
// available at http://www.PHPFront.com
//
// #### poll.php ####



include("admincp/config.php");

$user_ip $_SERVER['REMOTE_ADDR'];

$ipquery mysql_query("SELECT * FROM ips WHERE ip='$user_ip'");
$select_banned mysql_num_rows($ipquery);

if(
$select_banned){

    
//display results
    
    
    
$poll mysql_fetch_array(mysql_query("select * from poll"));
    
$totalvotes $poll['totalvotes'];
    
$question $poll['question'];
            
    echo(
"<div class=poll>$question<br /><br />");
    
    
$get_questions mysql_query("select * from options");
    while(
$r=mysql_fetch_array($get_questions)){
    
    
        
extract($r);
        
$per $votes 100 $totalvotes;
        
$per floor($per);
        
        echo 
htmlspecialchars($field); 
        
?> <strong><? echo("$votes"); ?></strong><br />
        <div style="background-color: <? echo config(bg1); ?>;"><div style="color: <? echo config(text); ?>; font-size: <? echo config(size); ?>px; text-align: right;background-color: <? echo config(bg2); ?>; width: <? echo($per); ?>%;"><? echo("$per%"); ?></div></div>
        <?
            
    
}
    
    echo(
"<br />Total de votos: <strong>$totalvotes</strong></div>"); 
    
    
    
    
    
}else{





//if the submit button was pressed
if($_POST['submit']){
    
    
//grab vars
    
$vote $_POST['vote'];
    
$refer $_POST['refer'];
    
        
    
//update numbers
    
$update_totalvotes "UPDATE poll SET totalvotes = totalvotes + 1";
    
$insert mysql_query($update_totalvotes);
    
    
$update_votes "UPDATE options SET votes = votes + 1 WHERE id = $vote";
    
$insert mysql_query($update_votes);
            
    
//add ip to stop multiple voting
    
$ip $_SERVER['REMOTE_ADDR'];
    
$addip mysql_query("INSERT INTO ips (ip)""VALUES ('$ip')"); 

    
    
//send the user back to thepage they were just viewing
    
header("Location: $refer");
    
    
        
}    
    
    
//display the form!
    
?><form action="<? $_SERVER['PHP_SELF']; ?>" method="post"><?
        
        
    $getcurrent 
mysql_query("select * from options ORDER by id");
    while(
$r=mysql_fetch_array($getcurrent)){
        
        
extract($r);
        
        
?><input type="radio" name="vote" value="<? echo($id); ?>" class="radiobutton" /> <? echo($field); ?><br /><?
        
    
}    
        
        
    
?>
    <input type="hidden" name="refer" value="<? echo $_SERVER['REQUEST_URI']; ?>" />
    <input type="submit" name="submit" value="Submit" /> 
    </form>
    <?    
    
    
    
}
        



?>
Espero vuestra ayuda, un saludo
  #2 (permalink)  
Antiguo 28/06/2007, 07:35
Avatar de jerkan  
Fecha de Ingreso: septiembre-2005
Mensajes: 1.607
Antigüedad: 18 años, 7 meses
Puntos: 19
Re: Pequeño fallo en una encuesta

Este error es muy común. Cuando haces una redirección con la función header:
Código PHP:
header("Location: $refer"); 
no debes haber mostrado nada (echos, prints) con anterioridad.
Según reza el error, printas algo en la línea 10 del fichero index.php.

Un saludo.
  #3 (permalink)  
Antiguo 28/06/2007, 07:56
Borjimante
Invitado
 
Mensajes: n/a
Puntos:
Re: Pequeño fallo en una encuesta

entonces si lo borro no pasa nada?¿

Aprovecho tambien para decir que el voton de votar no me aparece en el index.php y no se porque porque en poll.php existe el codigo.
  #4 (permalink)  
Antiguo 28/06/2007, 08:14
Avatar de jerkan  
Fecha de Ingreso: septiembre-2005
Mensajes: 1.607
Antigüedad: 18 años, 7 meses
Puntos: 19
Re: Pequeño fallo en una encuesta

Cita:
Iniciado por Borjimante Ver Mensaje
entonces si lo borro no pasa nada?¿
Si te refieres a borrar la línea del header, tú sabrás si quieres que se haga esa redirección o no.
Cita:
Iniciado por Borjimante Ver Mensaje
Aprovecho tambien para decir que el voton de votar no me aparece en el index.php y no se porque porque en poll.php existe el codigo.
Si no muestras el código del index.php no podemos ayudarte.
  #5 (permalink)  
Antiguo 28/06/2007, 08:22
Borjimante
Invitado
 
Mensajes: n/a
Puntos:
Re: Pequeño fallo en una encuesta

index.php

Código PHP:
<?
include("Fpoll/poll.php");
?>
  #6 (permalink)  
Antiguo 28/06/2007, 08:28
Avatar de jerkan  
Fecha de Ingreso: septiembre-2005
Mensajes: 1.607
Antigüedad: 18 años, 7 meses
Puntos: 19
Re: Pequeño fallo en una encuesta

Pues el index.php no llega a las 10 líneas.

Comprueba que no tengas espacios en blanco ni antes ni después de los <?, ?>
  #7 (permalink)  
Antiguo 28/06/2007, 08:30
Borjimante
Invitado
 
Mensajes: n/a
Puntos:
Re: Pequeño fallo en una encuesta

lo del boton votar ya no me importa ya lo he arreglado, el problema es la redireción

yo le pongo un

Código PHP:
header("Location: index.php"); 
y no hace nada, yo quiero que redireccione a los resultados despues de votar como podia hacer para que no diera fallo?¿
  #8 (permalink)  
Antiguo 28/06/2007, 09:06
 
Fecha de Ingreso: junio-2007
Mensajes: 19
Antigüedad: 16 años, 10 meses
Puntos: 1
Re: Pequeño fallo en una encuesta

Prueba con:

echo " <script language='JavaScript' type='text/JavaScript'> ";
echo " location.href='index.php' ";
echo " </script> ";
  #9 (permalink)  
Antiguo 28/06/2007, 09:25
Borjimante
Invitado
 
Mensajes: n/a
Puntos:
Re: Pequeño fallo en una encuesta

perfecto gracias
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:19.