Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/07/2011, 15:27
Kilin
 
Fecha de Ingreso: junio-2011
Mensajes: 92
Antigüedad: 12 años, 10 meses
Puntos: 3
Arreglar codigo UPDATE en PHP

Pues verán, he creado un sistema de noticias y comentarios a partir del tema de este blog, pero el archivo edit.php me está dando problemas.
el codigo que uso es este.

editar.php
Código:
<?php

$id=$_GET["id"];
$connect = mysql_connect("server","user","paswd");

mysql_select_db("database",$connect);

$result=mysql_query("select * from noticias where id_noticia='$id'",$connect);

while($row=mysql_fetch_array($result))
{?>
<style type="text/css">
<!--
.Estilo1 {font-family: Arial, Helvetica, sans-serif}
.Estilo2 {font-size: 24px}
body {
	background-color: #000000;
}
-->
</style>

<form action="edit.php" method="post">
  <table width="800" border="0" align="center" cellpadding="0" cellspacing="10">
  <tr>
    <td width="780" height="488" background="images/dentro1.png"><div align="center" class="Estilo1 Estilo2">Editar Noticia
        <input type="hidden" name="id" value = "<?php echo $row['id_noticia'];?>" />
    </div>
      <div align="center" class="Estilo1">
      <table width="534" border="0" cellspacing="10" cellpadding="0">
        <tr>
          <td width="177">T&iacute;tulo de la noticia </td>
          <td width="327"><input name="titulo" type="text" value="<?php echo $row['titulo']; ?>" size="50" /></td>
        </tr>
        <tr>
          <td height="29">Autor</td>
          <td><label>
            <select name="autor" id="autor">
              <option value="<?php echo $row['autor']; ?>" selected="selected"><?php echo $row['autor']; ?></option>
              <option value="Admin">Admin</option>
            </select>
          </label></td>
        </tr>
        <tr>
          <td>Categor&iacute;a</td>
          <td><label>
            <select name="categoria" id="categoria">
              <option value="<?php echo $row['categoria']; ?>" selected="selected"><?php echo $row['categoria']; ?></option>
              <option value="Foro">Foro</option>
              <option value="Web">Web</option>
              <option value="Blog">Blog</option>
              <option value="Ocio">Ocio</option>
              <option value="Tiempo Libre">Tiempo libre</option>
              <option value="Juegos">Juegos</option>
            </select>
          </label></td>
        </tr>
        <tr>
          <td>Noticia</td>
          <td><textarea name="articulo" cols="40" rows="10"><?php echo $row['noticia']; ?></textarea></td>
        </tr>
        <tr>
          <td>Imagen de la NOTICIA </td>
          <td><input name="imagen" type="text" value="<?php echo $row['imagen']; ?>" size="50" /></td>
        </tr>
      </table>
      <p><br />
            <input name="submit" type="submit" value="Publicar" />
            <br />
        </p>
      </div></td>
  </tr>
</table>
<p>&nbsp;</p></p>
  <p>
    <?php
}
mysql_free_result($result);
mysql_close($connect);

?>
  </p>
</form>  
<p><br>
</p>
</form>
edit.php
Código:
<?php
$id=$_POST['id'];
$titulo=$_POST['titulo'];
$autor=$_POST['autor'];
$categoria=$_POST['categoria'];
$noticia=$_POST['noticia'];
$imagen=$_POST['imagen'];


mysql_connect("server","user","passwd");

mysql_select_db("database);  
$sql = "UPDATE noticias SET id_noticia='$id', titulo='$titulo', autor='$autor', noticia='$noticia', categoria='$categoria', imagen='$imagen' WHERE id_noticia='$id'";

$result = mysql_query($sql, $link) or die("Error en consulta:".mysql_error() );

header("location: index.php");
?>
SEgún me dice, el error está en:
$sql = "UPDATE noticias SET id_noticia='$id', titulo='$titulo', autor='$autor', noticia='$noticia', categoria='$categoria', imagen='$imagen' WHERE id_noticia='$id'";

pero no veeo error ._.