Foros del Web » Programando para Internet » PHP »

(Ayuda) Encuesta algunos errores

Estas en el tema de (Ayuda) Encuesta algunos errores en el foro de PHP en Foros del Web. Hola q tal? Cree una encuesta y me da unos errores: En encuesta.php: $row = mysql_fetch_array($resultados); y en resultados.php $row = mysql_fetch_array($resultados); $res1= round ($row['valor1']*100/$row['total'],2); ...
  #1 (permalink)  
Antiguo 09/03/2008, 17:40
 
Fecha de Ingreso: marzo-2008
Mensajes: 1.020
Antigüedad: 16 años, 1 mes
Puntos: 21
(Ayuda) Encuesta algunos errores

Hola q tal?
Cree una encuesta y me da unos errores:
En encuesta.php:

$row = mysql_fetch_array($resultados);

y en resultados.php

$row = mysql_fetch_array($resultados);
$res1= round ($row['valor1']*100/$row['total'],2);
$res2= round ($row['valor2']*100/$row['total'],2);
$res3= round ($row['valor3']*100/$row['total'],2);

nose si hay alguna varible omitida, o falta algo.....
espero sus respuestas.
Gracias....salu2!
  #2 (permalink)  
Antiguo 09/03/2008, 17:43
 
Fecha de Ingreso: enero-2008
Mensajes: 132
Antigüedad: 16 años, 2 meses
Puntos: 6
Re: (Ayuda) Encuesta algunos errores

que errores?
  #3 (permalink)  
Antiguo 09/03/2008, 17:50
 
Fecha de Ingreso: marzo-2008
Mensajes: 1.020
Antigüedad: 16 años, 1 mes
Puntos: 21
Re: (Ayuda) Encuesta algunos errores

esos que marq ahi, cdo hago click en el link para ir a la encuesta :

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in I:\FerozoWebHosting\nutrimel.com.ar\public_html\en cuesta.php on line 20

esta es la linea 20: $row = mysql_fetch_array($resultados);

y cdo seleccionop algo de la encuesta, paso a resultados y me salen errores en las linesas 39-40-41-42:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in I:\FerozoWebHosting\nutrimel.com.ar\public_html\re sultados.php on line 39

Warning: Division by zero in I:\FerozoWebHosting\nutrimel.com.ar\public_html\re sultados.php on line 40

Warning: Division by zero in I:\FerozoWebHosting\nutrimel.com.ar\public_html\re sultados.php on line 41

Warning: Division by zero in I:\FerozoWebHosting\nutrimel.com.ar\public_html\re sultados.php on line 42

estas son las lineas de los supuestos errores en el codigo

$row = mysql_fetch_array($resultados);
$res1= round ($row['valor1']*100/$row['total'],2);
$res2= round ($row['valor2']*100/$row['total'],2);
$res3= round ($row['valor3']*100/$row['total'],2);

salu2!
  #4 (permalink)  
Antiguo 09/03/2008, 17:54
 
Fecha de Ingreso: enero-2008
Mensajes: 132
Antigüedad: 16 años, 2 meses
Puntos: 6
Re: (Ayuda) Encuesta algunos errores

$resultado gurda los datos de mysql_query por lo tanto ese query esta mal

y $row['total'] guarda el valor de 0 y no puedes dividir entre 0
  #5 (permalink)  
Antiguo 09/03/2008, 17:58
 
Fecha de Ingreso: marzo-2008
Mensajes: 1.020
Antigüedad: 16 años, 1 mes
Puntos: 21
Re: (Ayuda) Encuesta algunos errores

okis, gracias, pero soy novato y nose bien para donde salir...

que es un query y donde lo modifico para corregir el error???

Salu2!
  #6 (permalink)  
Antiguo 09/03/2008, 18:05
 
Fecha de Ingreso: enero-2008
Mensajes: 132
Antigüedad: 16 años, 2 meses
Puntos: 6
Re: (Ayuda) Encuesta algunos errores

muestra el codigo completo de tu script y te muestro el error
  #7 (permalink)  
Antiguo 09/03/2008, 18:08
 
Fecha de Ingreso: marzo-2008
Mensajes: 1.020
Antigüedad: 16 años, 1 mes
Puntos: 21
Re: (Ayuda) Encuesta algunos errores

encuesta.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<?
$servidor = "localhost";
$usuario = "w1070536";
$password = "kuzufiSO13";
$base_de_datos = "w1070536_encuesta";
$conextar=mysql_connect ($servidor,$usuario,$password);
mysql_select_db($base_de_datos);
$sqlupdate = "UPDATE encuestas SET valor$voto = valor$voto+1, total = total+1";
mysql_query($sqlupdate,$conextar);
$sql = "SELECT * FROM encuestas ORDER BY idencuesta desc LIMIT 1";
$resultados = mysql_query($sql,$conextar);
$row = mysql_fetch_array($resultados);
?>
<script type="text/javascript" language="JavaScript">
function resultados(){
window.open("resultados.php","","toolbar=0,locatio n=0,directories=0,status=0,menubar=0,scrollbars=0, resizable=0,width=320,height=200");
}
</script>
<form name="form1" method="post" action="<?= $PHP_SELF?>">
<table width="256" border="0" align="center" cellpadding="0" cellspacing="0" class="forumline">
<tr valign="baseline">
<td colspan="2" class="row1">
<?=$row['¿Quién ganará el torneo?']; ?>
<br>
</td>
</tr>
<tr>
<td width="110">
<?=$row['Boca'];?>
Boca</td>
<td width="146"><input type="radio" name="voto" value="1">
</td>
</tr>
<tr>
<td>
<?=$row['River'];?>River
</td>
<td><input type="radio" name="voto" value="2"></td>
</tr>
<tr>
<td>
<?=$row['Lanus'];?>Lanus
</td>
<td><input type="radio" name="voto" value="3"></td>
</tr>
<tr align="center">
<td height="20" colspan="2"><input type="submit" class="post"name="Submit" value="Votar" onClick=window.open("resultados.php","","toolbar=0 ,location=0,directories=0,status=0,menubar=0,scrol lbars=0,resizable=0,width=320,height=200");
></td>
</tr>
</table>
<p>&nbsp;</p></form>
</body>
</html>
  #8 (permalink)  
Antiguo 09/03/2008, 18:09
 
Fecha de Ingreso: marzo-2008
Mensajes: 1.020
Antigüedad: 16 años, 1 mes
Puntos: 21
Re: (Ayuda) Encuesta algunos errores

resultados.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<html>
<head>
<title>Resultados de la encuesta</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
background-color: #FFFFDD;
}
td {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
}
-->
</style>
</head>
<body>
<?
$servidor = "localhost";
$usuario = "w1070536";
$password = "kuzufiSO13";
$base_de_datos = "w1070536_encuesta";
$conextar=mysql_connect ($servidor,$usuario,$password);
mysql_select_db($base_de_datos);
//$sqlupdate = "UPDATE encuestas SET valor$voto = valor$voto+1, total = total+1";
//mysql_query($sqlupdate,$conextar);
$sql = "SELECT * FROM encuestas ORDER BY idencuesta desc LIMIT 1";
$resultados = mysql_query($sql,$conextar);
$row = mysql_fetch_array($resultados);
$res1= round ($row['valor1']*100/$row['total'],2);
$res2= round ($row['valor2']*100/$row['total'],2);
$res3= round ($row['valor3']*100/$row['total'],2);
?>
<p>Resultados parciales de la encuesta</p>
<?=$row['¿Quién ganará el torneo?']; ?><br>
<br>

<TABLE WIDTH="300" BORDER="1" ALIGN="center" BORDERCOLOR="#3097A3">
<TR>
<TD WIDTH="100"><?=$row['Boca']; ?></TD>
<TD WIDTH="*"><IMG SRC="barra.gif" WIDTH="15" HEIGHT="25" border="0"></TD>
<TD ALIGN="center" WIDTH="70"><? echo $res1."%";?> </TD>
</TR>
<TR>
<TD WIDTH="100" ><?=$row['River']; ?></TD>
<TD WIDTH="*"><IMG SRC="barra.gif" WIDTH="15" HEIGHT="25" border="0"></TD>
<TD ALIGN="center" WIDTH="70"><? echo $res2."%";?> </TD>
</TR>
<TR>
<TD WIDTH="100"><?=$row['Lanus']; ?></TD>
<TD WIDTH="*"><IMG HEIGHT="25" WIDTH="15" SRC="barra.gif"></TD>
<TD ALIGN="center" WIDTH="70"><? echo $res3."%";?> </TD>
</TR>
</TABLE>
<form name="form1" method="post" action="">
<div align="center">
<p>
<input type="submit" name="Submit" value="Cerrar Ventana" onclick="window.close();">
</p>
<p>&nbsp; </p>
</div>
</form>
</body>
</html>
</body>
</html>
  #9 (permalink)  
Antiguo 09/03/2008, 18:18
 
Fecha de Ingreso: enero-2008
Mensajes: 132
Antigüedad: 16 años, 2 meses
Puntos: 6
Re: (Ayuda) Encuesta algunos errores

cambia esto
$resultados = mysql_query($sql,$conextar);

por esto

resultados = mysql_query($sql,$conextar) or die(mysql_error());

y te saldra una descripcion del error en ese query
  #10 (permalink)  
Antiguo 09/03/2008, 18:59
 
Fecha de Ingreso: marzo-2008
Mensajes: 1.020
Antigüedad: 16 años, 1 mes
Puntos: 21
Re: (Ayuda) Encuesta algunos errores

me sale esto:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in I:\FerozoWebHosting\nutrimel.com.ar\public_html\en cuesta.php on line 20

linea 20:
$row = mysql_fetch_array($resultados);

lo que hice fue reemplazar lo que me dijiste en el rchivo resultados php.

al codigo lo saque de este foro: (pongo la direccionasi pelada pq no puedo postear corrctamente los links)

http://www.forosdelweb.com/f18/indice-faqs-php-108208/
  #11 (permalink)  
Antiguo 10/03/2008, 03:37
 
Fecha de Ingreso: marzo-2008
Mensajes: 1.020
Antigüedad: 16 años, 1 mes
Puntos: 21
Re: (Ayuda) Encuesta algunos errores

no hay caso, no quiere componerese esto....tendre que configurar algo del panel de cotrol del servidor???

salu2!
  #12 (permalink)  
Antiguo 10/03/2008, 11:32
 
Fecha de Ingreso: marzo-2008
Mensajes: 1.020
Antigüedad: 16 años, 1 mes
Puntos: 21
Re: (Ayuda) Encuesta algunos errores

ayudaa pleasee!!!
no llego a compender o a ubicar donde esta el posible error....
  #13 (permalink)  
Antiguo 10/03/2008, 14:49
Avatar de pato12  
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 6 meses
Puntos: 101
Re: (Ayuda) Encuesta algunos errores

Prueba con esto:
Encuesta:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<? 
$servidor 
"localhost"
$usuario "w1070536"
$password "kuzufiSO13"
$base_de_datos "w1070536_encuesta"
$conextar=mysql_connect ($servidor,$usuario,$password); 
mysql_select_db($base_de_datos); 
$sqlupdate "UPDATE encuestas SET valor$voto = valor$voto+1, total = total+1"
mysql_query($sqlupdate,$conextar); 
$sql "SELECT * FROM encuestas ORDER BY idencuesta desc LIMIT 1"
$row mysql_fetch_array($sql); 
?> 
<script type="text/javascript" language="JavaScript"> 
function resultados(){ 
window.open("resultados.php","","toolbar=0,locatio n=0,directories=0,status=0,menubar=0,scrollbars=0, resizable=0,width=320,height=200"); 

</script> 
<form name="form1" method="post" action="<?= $PHP_SELF?>"> 
<table width="256" border="0" align="center" cellpadding="0" cellspacing="0" class="forumline"> 
<tr valign="baseline"> 
<td colspan="2" class="row1"> 
<?=$row['¿Quién ganará el torneo?']; ?> 
<br> 
</td> 
</tr> 
<tr> 
<td width="110"> 
<?=$row['Boca'];?> 
Boca</td> 
<td width="146"><input type="radio" name="voto" value="1"> 
</td> 
</tr> 
<tr> 
<td> 
<?=$row['River'];?>River
</td> 
<td><input type="radio" name="voto" value="2"></td> 
</tr> 
<tr> 
<td> 
<?=$row['Lanus'];?>Lanus
</td> 
<td><input type="radio" name="voto" value="3"></td> 
</tr> 
<tr align="center"> 
<td height="20" colspan="2"><input type="submit" class="post"name="Submit" value="Votar" onClick=window.open("resultados.php","","toolbar=0 ,location=0,directories=0,status=0,menubar=0,scrol lbars=0,resizable=0,width=320,height=200"); 
></td> 
</tr> 
</table> 
<p>&nbsp;</p></form> 
</body>
</html>
resultados.php
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<html> 
<head> 
<title>Resultados de la encuesta</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<style type="text/css"> 
<!-- 
body { 
font-family: Verdana, Arial, Helvetica, sans-serif; 
font-size: 10px; 
background-color: #FFFFDD; 

td { 
font-family: Verdana, Arial, Helvetica, sans-serif; 
font-size: 10px; 

--> 
</style> 
</head> 
<body> 
<? 
$servidor 
"localhost"
$usuario "w1070536"
$password "kuzufiSO13"
$base_de_datos "w1070536_encuesta"
$conextar=mysql_connect ($servidor,$usuario,$password); 
mysql_select_db($base_de_datos); 
//$sqlupdate = "UPDATE encuestas SET valor$voto = valor$voto+1, total = total+1"; 
//mysql_query($sqlupdate,$conextar); 
$sql "SELECT * FROM encuestas ORDER BY idencuesta desc LIMIT 1"
$row mysql_fetch_array($sql); 
$res1round ($row['valor1']*100/$row['total'],2); 
$res2round ($row['valor2']*100/$row['total'],2); 
$res3round ($row['valor3']*100/$row['total'],2); 
?> 
<p>Resultados parciales de la encuesta</p> 
<?=$row['¿Quién ganará el torneo?']; ?><br> 
<br> 

<TABLE WIDTH="300" BORDER="1" ALIGN="center" BORDERCOLOR="#3097A3"> 
<TR> 
<TD WIDTH="100"><?=$row['Boca']; ?></TD> 
<TD WIDTH="*"><IMG SRC="barra.gif" WIDTH="15" HEIGHT="25" border="0"></TD> 
<TD ALIGN="center" WIDTH="70"><? echo $res1."%";?> </TD> 
</TR> 
<TR> 
<TD WIDTH="100" ><?=$row['River']; ?></TD> 
<TD WIDTH="*"><IMG SRC="barra.gif" WIDTH="15" HEIGHT="25" border="0"></TD> 
<TD ALIGN="center" WIDTH="70"><? echo $res2."%";?> </TD> 
</TR> 
<TR> 
<TD WIDTH="100"><?=$row['Lanus']; ?></TD> 
<TD WIDTH="*"><IMG HEIGHT="25" WIDTH="15" SRC="barra.gif"></TD> 
<TD ALIGN="center" WIDTH="70"><? echo $res3."%";?> </TD> 
</TR> 
</TABLE> 
<form name="form1" method="post" action=""> 
<div align="center"> 
<p> 
<input type="submit" name="Submit" value="Cerrar Ventana" onclick="window.close();"> 
</p> 
<p>&nbsp; </p> 
</div> 
</form> 
</body> 
</html> 
</body>
</html>
Si no te anda, deve ser la tabla.

Suerte
Salu2
__________________
Half Music - www.halfmusic.com
  #14 (permalink)  
Antiguo 11/03/2008, 06:52
 
Fecha de Ingreso: marzo-2008
Mensajes: 1.020
Antigüedad: 16 años, 1 mes
Puntos: 21
Re: (Ayuda) Encuesta algunos errores

muchas gracias por responderr....

Surge otro error en la linea 27:

Linea 26: $sql = "SELECT * FROM encuestas ORDER BY idencuesta desc LIMIT 1";
Linea 27: $row = mysql_fetch_array($sql);



este es el arror que me marca cdo accedo:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in I:\FerozoWebHosting\nutrimel.com.ar\public_html\en cuesta.php on line 27

q es eso de las tablas?
salu2!

Última edición por opzina; 11/03/2008 a las 06:58
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

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 00:10.