Foros del Web » Programando para Internet » PHP »

advertencia php

Estas en el tema de advertencia php en el foro de PHP en Foros del Web. hola a todos, pues eso me salen errorres de advertencia en un carrito de compras php, los errores son estos Advertencia : mysql_fetch_assoc () espera ...
  #1 (permalink)  
Antiguo 13/09/2011, 13:21
 
Fecha de Ingreso: diciembre-2010
Ubicación: tenerife
Mensajes: 60
Antigüedad: 13 años, 4 meses
Puntos: 0
advertencia php

hola a todos, pues eso me salen errorres de advertencia en un carrito de compras php, los errores son estos

Advertencia : mysql_fetch_assoc () espera un parámetro a ser el recurso, boleano dado en C: \ xampp \ htdocs \ Proyecto \ catalogo.php on line 34

Advertencia : mysql_fetch_assoc () espera un parámetro a ser el recurso, boleano dado en C: \ xampp \ htdocs \ Proyecto \ catalogo.php on line 34


este disitnto me sale en AGREGACAR


dvertencia : mysql_fetch_array () espera un parámetro a ser el recurso, boleano dado en C: \ xampp \ htdocs \ Proyecto \ agregacar.php en la línea 9

Advertencia : No se puede modificar la información de cabecera - cabeceras ya enviado por (la producción comenzó en C: \ xampp \ htdocs \ Proyecto \ agregacar.php: 9) en C: \ xampp \ htdocs \ Proyecto \ agregacar.php on line 16

os copio los codigos a ver q tal

VER CARRITO
<?php
session_start();
if(isset($_SESSION['carro']))
$carro=$_SESSION['carro'];else $carro=false;
?>
<html>
<head>
<title>PRODUCTOS AGREGADOS AL CARRITO</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.tit {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
color: #FFFFFF;
}
.prod {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
color: #333333;
}
h1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 20px;
color: #990000;
}
-->
</style>
</head>
<body>
<h1 align="center">Carrito</h1>
<?php
if($carro){

?>
<table width="720" border="0" cellspacing="0" cellpadding="0" align="center">
<tr bgcolor="#333333" class="tit">
<td width="105">Producto</td>
<td width="207">Precio</td>
<td colspan="2" align="center">Cantidad de Unidades</td>
<td width="100" align="center">Borrar</td>
<td width="159" align="center">Actualizar</td>
</tr>
<?php
$color=array("#ffffff","#F0F0F0");
$contador=0;

$suma=0;

foreach($carro as $k => $v){

$subto=$v['cantidad']*$v['precio'];
$suma=$suma+$subto;
$contador++;

?>
<form name="a<?php echo $v['identificador'] ?>" method="post" action="agregacar.php?<?php echo SID ?>" id="a<?php echo $v['identificador'] ?>">
<tr bgcolor="<?php echo $color[$contador%2]; ?>" class='prod'>
<td><?php echo $v['producto'] ?></td>
<td><?php echo $v['precio'] ?></td>
<td width="43" align="center"><?php echo $v['cantidad'] ?></td>
<td width="136" align="center">
<input name="cantidad" type="text" id="cantidad" value="<?php echo $v['cantidad'] ?>" size="8">
<input name="id" type="hidden" id="id" value="<?php echo $v['id'] ?>"> </td>
<td align="center"><a href="borracar.php?<?php echo SID ?>&id=<?php echo $v['id'] ?>"><img src="trash.gif" width="12" height="14" border="0"></a></td>
<td align="center">
<input name="imageField" type="image" src="actualizar.gif" width="20" height="20" border="0"></td>
</tr></form>
<?php

}
?>
</table>
<div align="center"><span class="prod">Total de Artículos: <?php echo count($carro);

?></span>
</div><br>
<div align="center"><span class="prod">Total: $<?php echo number_format($suma,2);

?></span>
</div><br>
<div align="center"><span class="prod">Continuar la selección de productos</span>
<a href="catalogo.php?<?php echo SID;?>">
<img src="continuar.gif" width="13" height="13" border="0"></a>
</div>
<?php }else{ ?>
<p align="center"> <span class="prod">No hay productos seleccionados</span>
<a href="catalogo.php?<?php echo SID;?>">
<img src="continuar.gif" width="13" height="13" border="0"></a>
<?php }?>
</p>
</body>
</html>

AGREGACAR
<?php
session_start();
extract($_REQUEST);
$id=$_GET['id'];
mysql_connect("localhost","root","");
mysql_select_db("carrito de compras");
if(!isset($cantidad)){$cantidad=1;}
$qry=mysql_query("select * from catalogo where id='".$id."'");
$row=mysql_fetch_array($qry);
if(isset($_SESSION['carro']))
$carro=$_SESSION['carro'];
$carro[md5($id)]=array('identificador'=>md5($id),
'cantidad'=>$cantidad,'producto'=>$row['producto'],
'precio'=>$row['precio'],'id'=>$id);
$_SESSION['carro']=$carro;
header("Location:catalogo.php?".SID);
?>

BORRACAR

<?php
session_start();
extract($_GET);
$carro=$_SESSION['carro'];
unset($carro[md5($id)]);
$_SESSION['carro']=$carro;
header("Location:catalogo.php?".SID);
?>

CATALOGO

<?php
ob_start("ob_gzhandler");
session_start();
mysql_connect("localhost","root","");
mysql_select_db("carrito de compras");
if(isset($_SESSION['carro']))
$carro=$_SESSION['carro'];else $carro=false;
$qry=mysql_query("select * from catalogo order by producto asc");
?>
<html>
<head>
<title>CAT&Aacute;LOGO</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.catalogo {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
color: #333333;
}
-->
</style>
</head>
<body>
<table width="272" align="center" cellpadding="0" cellspacing="0" style="border: 1px solid #000000;">
<tr valign="middle" bordercolor="#FFFFFF" bgcolor="#DFDFDF" class="catalogo">
<td width="170"><strong>Producto</strong></td>
<td width="77"><strong>Precio</strong></td>
<td width="25" align="right"><a href="vercarrito.php?<?php echo SID ?>" title="Ver el contenido del carrito">
<img src="vercarrito.gif" width="25" height="21" border="0"></a></td>
</tr>
<?php

while($row=mysql_fetch_assoc($qry)){
?>
<tr valign="middle" class="catalogo">
<td><?php echo $row['producto'] ?></td>
<td><?php echo $row['precio'] ?></td>
<td align="center">
<?php
if(!$carro || !isset($carro[md5($row['id'])]['identificador']) || $carro[md5($row['id'])]['identificador']!=md5($row['id'])){

?>
<a href="agregacar.php?<?php echo SID ?>&id=<?php echo $row['id']; ?>">
<img src="productonoagregado.gif" border="0" title="Agregar al Carrito"></a><?php }else

{?><a href="borracar.php?<?php echo SID ?>&id=<?php echo $row['id']; ?>">
<img src="productoagregado.gif" border="0" title="Quitar del Carrito"></a><?php } ?></td>
</tr><?php } ?>
</table>
</body>
</html>
<?php
ob_end_flush();
?>

a ver si logro arreglarlo, muchas gracias
  #2 (permalink)  
Antiguo 13/09/2011, 14:27
Avatar de Eleazan  
Fecha de Ingreso: abril-2008
Ubicación: Ibiza
Mensajes: 1.879
Antigüedad: 16 años
Puntos: 326
Respuesta: advertencia php

Fácil:

Los 3 errores de "mysql_fetch_assoc () espera un parámetro a ser el recurso, boleano dado en blablabla" significan lo mismo:

El recurso (el resultado de mysql_query) es erróneo.

Eso quiere decir:
1) No está bien formada la query
2) No conecta con el host

Para comprobarlo, deberías, en el query, por ejemplo, poner

Código PHP:
if( $qry mysql_query("SELECT * FROM `blabla`") ) {
  
//Codigo a ejecutar si todo va bien
}
else {
   echo 
'Fallo en la consulta SQL: '.mysql_error();

Por ejemplo. Así sabrás si es culpa de la query ;)
PD: Deberías acostumbrarte a comprobar si una funcion tiene éxito, o si falla ;)

PD2: Por favor, la próxima vez, coloca el código con el Highlight que te sale apropiado para tu código, no es muy dificil, y nos ayuda a todos a leer tu código :)
__________________
>> Eleazan's Source
>> @Eleazan
  #3 (permalink)  
Antiguo 14/09/2011, 06:49
 
Fecha de Ingreso: diciembre-2010
Ubicación: tenerife
Mensajes: 60
Antigüedad: 13 años, 4 meses
Puntos: 0
Respuesta: advertencia php

me sigue saliendo el mismo error , aunq ya lo cambie
Código PHP:
Ver original
  1. <?php
  2. ob_start("ob_gzhandler");
  3. mysql_connect("localhost","root","");
  4. mysql_select_db("carrito de compras");
  5. if(isset($_SESSION['carro']))
  6. $carro=$_SESSION['carro'];else $carro=false;
  7. $qry=mysql_query("select * from catalogo order by producto asc");
  8. ?>
  9. <html>
  10. <head>
  11. <title>CAT&Aacute;LOGO</title>
  12. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  13. <style type="text/css">
  14. <!--
  15. .catalogo {
  16. font-family: Verdana, Arial, Helvetica, sans-serif;
  17. font-size: 9px;
  18. color: #333333;
  19. }
  20. -->
  21. </style>
  22. </head>
  23. <body>
  24. <table width="272" align="center" cellpadding="0" cellspacing="0" style="border: 1px solid #000000;">
  25. <tr valign="middle" bordercolor="#FFFFFF" bgcolor="#DFDFDF" class="catalogo">
  26. <td width="170"><strong>Producto</strong></td>
  27. <td width="77"><strong>Precio</strong></td>
  28. <td width="25" align="right"><a href="vercarrito.php?<?php echo SID ?>" title="Ver el contenido del carrito">
  29. <img src="vercarrito.gif" width="25" height="21" border="0"></a></td>
  30. </tr>
  31. <?php
  32.  
  33. while($row=mysql_fetch_assoc($qry)){
  34. if( $qry = mysql_query("SELECT * FROM 'catalogo' where id='".$id."'") ) {
  35.  
  36. }
  37. else {
  38.    echo 'Fallo en la consulta SQL: '.mysql_error();
  39. }  
  40.    
  41. ?>
  42. <tr valign="middle" class="catalogo">
  43. <td><?php echo $row['producto'] ?></td>
  44. <td><?php echo $row['precio'] ?></td>
  45. <td align="center">
  46. <?php
  47. if(!$carro || !isset($carro[md5($row['id'])]['identificador']) || $carro[md5($row['id'])]['identificador']!=md5($row['id'])){
  48.  
  49. ?>
  50. <a href="agregacar.php?<?php echo SID ?>&id=<?php echo $row['id']; ?>">
  51. <img src="productonoagregado.gif" border="0" title="Agregar al Carrito"></a><?php }else
  52.  
  53. {?><a href="borracar.php?<?php echo SID ?>&id=<?php echo $row['id']; ?>">
  54. <img src="productoagregado.gif" border="0" title="Quitar del Carrito"></a><?php } ?></td>
  55. </tr><?php }?>
  56. </table>
  57. </body>
  58. </html>
  59. <?php
  60. ?>
  #4 (permalink)  
Antiguo 14/09/2011, 07:23
Avatar de Eleazan  
Fecha de Ingreso: abril-2008
Ubicación: Ibiza
Mensajes: 1.879
Antigüedad: 16 años
Puntos: 326
Respuesta: advertencia php

Deberías cambiarlo más arriba (no se pq lo haces así :S)

Algo así como:
Código PHP:
ob_start("ob_gzhandler");
mysql_connect("localhost","root","");
mysql_select_db("carrito de compras");
if(isset(
$_SESSION['carro']))
$carro=$_SESSION['carro'];else $carro=false;
if(
$qry=mysql_query("select * from catalogo order by producto asc")) {
//Aqui el resto del codigo
}
else  echo 
'Algo ha ido mal en la SQL: '.mysql_error(); 
__________________
>> Eleazan's Source
>> @Eleazan

Etiquetas: advertencia, html, mysql, sql
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 03:16.