Foros del Web » Programando para Internet » PHP »

Edicion de noticias

Estas en el tema de Edicion de noticias en el foro de PHP en Foros del Web. Estoy desarrollando un sistema de noticias, iva bien hasta que intente hacer un formulario con el cual pudiera editar una noticia Al principio parecia que ...
  #1 (permalink)  
Antiguo 14/07/2005, 14:14
Avatar de rigtersir  
Fecha de Ingreso: enero-2004
Ubicación: Mexico City
Mensajes: 28
Antigüedad: 20 años, 3 meses
Puntos: 0
Exclamación Edicion de noticias

Estoy desarrollando un sistema de noticias, iva bien hasta que intente hacer un formulario con el cual pudiera editar una noticia
Al principio parecia que todo andaba bien pero al agregar una segunda noticia y editarla supuestamente lo hacia....pero aqui el problema, tambien modificaba las noticias que estaban antes, es decir la edicion se hacia pero modificaba los datos de otras noticias con datos identicos, toda la tabla de noticias era igual

Cuando comence logre mostrar los titulos de las noticias dentro de un select y que al seleccionar alguna opcion me apareciera esta dentro de un formulario. Aqui el codigo:

edit.php
Código PHP:
<?
include ("config.php");
mysql_connect("$host","$usuario","$password");

echo 
'<FORM METHOD="POST" ACTION="edit.php?accion=show"><b>Editar Noticia</b><br><br>';

$sSQL="Select title From news Order By id";
$result=mysql_db_query("$nombredb",$sSQL);

echo 
'<select name="title">';

while (
$row=mysql_fetch_array($result))
{echo 
'<option>'.$row["title"];}
mysql_free_result($result)

?>

</select>
<INPUT TYPE="SUBMIT" value="Editar">
</FORM>
</center>
<?

if($accion=="show"){

$title$_POST['title'];
$query mysql_query("SELECT * FROM rps_news where title='$title'");

while(
$row mysql_fetch_array($query)){

echo 
"<center><b>Editar Noticia</b></center><br>
<center><form method=post action=edit2.php?action=editn>
<table border=0 width=10% cellpadding=0 height=21>
<tr>
<td width=153% height=1 align=right>Autor:</td>
<td width=74% height=1>&nbsp;<input type=text name=autor size=25 value=$row[autor]></td>
</tr>
<tr>
<td width=153% height=21 align=right>E-mail:</td>
<td width=74% height=21>&nbsp;<input type=text name=email size=25 value=$row[email]></td>
</tr>
<tr>
<td width=153% height=21 align=right>Fecha:</td>
<td width=74% height=21>&nbsp;<input type=text name=fecha size=25 value=$row[fecha]></td>
</tr>
<tr>
<td width=153% height=21 align=right>Imagen:</td>
<td width=74% height=21>&nbsp;<input type=text name=imagen size=25 value=$row[imagen]></td>
</tr>
<tr>
<td width=153% height=16 align=right>
Titulo:</td>
<td width=74% height=16>&nbsp;<textarea name=title rows=1 cols=25>$row[title]</textarea></td>
</tr>
<tr>
<td width=153% height=21 align=right>
Texto:</td>
<td width=74% height=21>&nbsp;<textarea rows=8 name=noticia cols=56>$row[noticia]</textarea></td>
</tr>
<tr>
<td width=153% height=21 align=right></td>
<td width=74% height=21>
<p align=center><input type=submit value=Editar name=editar>
</td>
</tr>
</table>
</form></center>"
;
}
}
?>
edit2.php
Código PHP:
<?php
include("config.php");

if(
$action=="editn"){

$sql "UPDATE rps_news set autor='$autor',email='$email',fecha='$fecha',imagen='$imagen',title='$title',noticia='$noticia'";

$resp mysql_query($sql);

echo 
"<center><font color=#990000 face=Tahoma size=1><b>Noticia Editada</b></font><br>
<a href=edit.php>Volver</a></center>"
;

}

?>
Ojala alguien me pueda ayudar a resolver este problemam se los agradeceria mucho
__________________
° Rigter °
Portfolio & Blog
http://www.rigtersir.com
  #2 (permalink)  
Antiguo 14/07/2005, 14:27
Avatar de PabloP  
Fecha de Ingreso: marzo-2005
Mensajes: 83
Antigüedad: 19 años, 1 mes
Puntos: 0
Puede ser que donde esta el update no le indicas un WHERE que diga cual es la noticia que quieres modificar
  #3 (permalink)  
Antiguo 15/07/2005, 04:54
Avatar de tunait
Moderadora
 
Fecha de Ingreso: agosto-2001
Ubicación: Terok Nor
Mensajes: 16.805
Antigüedad: 22 años, 8 meses
Puntos: 381
Cita:
Iniciado por PabloP
Puede ser que donde esta el update no le indicas un WHERE que diga cual es la noticia que quieres modificar
Efectivamente te faltó incluir la cláusula where indicando el registro que quieres modificar

Código:
$sql = "UPDATE rps_news set autor='$autor',email='$email',fecha='$fecha',image  n='$imagen',title='$title',noticia='$noticia' where title='$title'";
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 17:57.