Jump to content


Photo

ayuda error mysql_fetch_assoc(): supplied argument is not a valid MySQL


  • Please log in to reply
1 reply to this topic

#1 armonick

armonick

    Member

  • Miembros
  • PipPip
  • 41 posts

Posted 21 December 2011 - 04:52 PM

Hola,

No entiendo porque me da este error en la linea 21:

El método es el siguiente:

public function get_noticias_by_id($id_noticia)
{
$sql="select * from noticias where id_noticia'".strip_tags($id_noticia)."'";
$res=mysql_query($sql,Conectar::con());
while ($reg=mysql_fetch_assoc($res)) //esta es la linea 21
{
$this->noticia[]=$reg;
}
return $this->noticia;
}


Por otro lado pongo el fichero editar_noticia.php que es el que utiliza el método:

<?php
require_once("class/class_noticias.php");
$not=new Noticias();
if (isset($_POST) and $_POST["grabar"]=="si")
{
$not->edit_noticia();
exit;
}
$noticia=$not->get_noticias_by_id($_GET["id_noticia"]);

if (isset($_SESSION["acceso"]) and isset($_SESSION["sesion_perfil"]))
{
//print_r($_SESSION);
$t=new Trabajo();
$nom=$t->saluda_al_usuario($_SESSION["acceso"]);
$perfil=$t->get_perfil_por_id();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Editar Noticia <?php echo $noticia[0]["titulo"]; ?></title>
<!--<style type="text/css">
a{font-family:Verdana; font-size:11px; text-decoration:none;}
</style>-->
<script type="text/javascript" src="js/prettyForms.js"></script>
<link rel="stylesheet" href="css/estilos_formularios.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/menu_admin.css" type="text/css" media="screen" />
</head>

<body onload="prettyForms()">

<div id="cabecera">
<h1>BackEnd de tu perfil</h1>

<div id="sesion">
<?php echo "Hola ".$nom[0]["nombre"]." bienvenid@";?> tu perfil es <?php echo $perfil[0]["perfil"];?>
<br/>
<a href="salir.php">Cerrar Sesi&oacute;n</a>
</div>
</div>

<div id="menu-horizontal">
<?php include("menuadmin.php");?>
</div>

<!--<a href="home.php"><img src="ima/flechaverdeizq.PNG" title="Volver atrás" border="0"/></a>-->




<div id="derecha">
<div id="stylized" class="myform">
<form name="form" action="" method="post">
<h1>Editar notícia <?php echo $noticia[0]["titulo"]; ?></h1>
<fieldset id="form">
<legend>Notícia</legend>
<label>Título:<span class="small">Introduce el título</span></label>
<input type="text" name="titulo" id="name" value="<?php echo $noticia[0]["titulo"]; ?>" size="50"/>
<br/>
<br/>
<br/>
<label>Categoría:<span class="small">Escoge la categoría</span></label>
<?php
$n=$not->get_categoria();
?>
<select name="id_categoria">
<option value="0">Seleccione...</option>
<?php
for ($i=0;$i<sizeof($n);$i  )
{
if($n[$i]["id_categoria"] == $noticia[0]["id_categoria"])
{
?>
<option value="<?php echo $n[$i]["id_categoria"];?>" title="<?php echo $n[$i]["categoria"];?>" selected="selected"><?php echo $n[$i]["categoria"];?></option>
<?php
}else
{
?>
<option value="<?php echo $n[$i]["id_categoria"];?>" title="<?php echo $n[$i]["categoria"];?>"><?php echo $n[$i]["categoria"];?></option>
<?php
}


}
?>
</select>
<br/>
<br/>
<br/>
<label>Texto: <span class="small">Escribe la notícia</span></label>
<textarea type="text" name="texto" value="<?php echo $noticia[0]["texto"]; ?>" cols="57" rows="15" /></textarea>

</fieldset>
<fieldset>
<legend>Vídeo</legend>
<label>Enlace Vídeo:<span class="small">No es obligatorio </span></label>
<input type="textbox" name="enlace" value="<?php echo $noticia[0]["html"]; ?>" size="50" />
</fieldset>
<input type="hidden" name="grabar" value="si" />
<input type="hidden" name="id_noticia" value="<?php echo $_GET["id_noticia"];?>"/>
<p align="center"><input type="button" value="Editar Noticia" title="Editar Noticia" class="btn" onclick="document.form.submit();" /></p>
</form>
</div>
</div>




</body>
</html>
<?php
}else
{
echo "
<script type='text/javascript'>
alert('Debe loguearse primero para acceder a este contenido');
window.location='logreg.php';
</script>
";
}
?>


No entiendo porque me da el error: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /homez.433/odima/www/proyecto/prueba/tutorial10_blog1_con_registro_de_usuarios/class/class_noticias.php on line 21

No sé que es lo que puede ocurrir. No hay caracteres extraños, que yo haya visto.

Gracias por vuestra ayuda.

Saludos,

Armonick,
  • 0

#2 armonick

armonick

    Member

  • Miembros
  • PipPip
  • 41 posts

Posted 21 December 2011 - 05:07 PM

Me respondo a mí mismo jejeje.

Me faltaba un = en el sql:

$sql="select * from noticias where id_noticia'".strip_tags($id_noticia)."'"; //incorrecta
$sql="select * from noticias where id_noticia='".strip_tags($id_noticia)."'";//correcta

  • 0




IP.Board spam blocked by CleanTalk.