viernes, 27 de marzo de 2015

Actualizar/Editar tablas de BD PHP

//Formulario de edicion de datos


<?php
 
 include("conexion.php");

 $id_noti = $_GET['id_noti'];
 $sql = "SELECT * FROM noticia WHERE id_noticia = '$id_noti'";
 $result = mysql_query($sql);
 $row = mysql_fetch_array($result);

?>


<html>
<head>
</head>
<body>
 <form action =  "noticia_editada_save.php?id_noti=<?php echo $id_noti; ?>" method="POST">
  <table align = "center" style = "cellpadding 10px; cellspacing: 10px;">
   <tr>
       <td>Titulo:</td>
       <td>
           <input type = "text" name = "titulo" style = "width: 100%" value = "<?php echo $row['titulo']; ?>"/>
       </td>
   </tr>
   <tr>
       <td>Noticia:</td>
       <td>
           <textarea name = "cuerpo" rows = "5" cols = "60"><?php echo $row['cuerpo']; ?></textarea>
       </td>
   </tr>
   <tr>
       <td><input type = "submit" value = "Ingresar Datos"/></td>
   </tr>
  </table>
 </form> 
</body>
</html>



//Actualizacion de campos de la tabla de BD (noticia_editada_save.php) 

<?php 
 include('conexion.php');
 $id_noti = $_GET['id_noti'];
 $cuerpo = $_POST['cuerpo']; 
 $titulo = $_POST['titulo']; 

 $sql = "UPDATE noticia 
 SET titulo='$titulo', cuerpo='$cuerpo'
 WHERE id_noticia='$id_noti'"; 
 mysql_query($sql); 

 header("Location: admin.php");
?>

No hay comentarios:

Publicar un comentario