Ver Mensaje Individual
  #86 (permalink)  
Antiguo 03/05/2010, 03:49
Avatar de Flow89
Flow89
 
Fecha de Ingreso: abril-2010
Ubicación: Valladolid
Mensajes: 346
Antigüedad: 14 años
Puntos: 1
Respuesta: Gestor de Noticias para HTML con PHP [novato]

Cita:
Iniciado por Heli0s Ver Mensaje
Para hacer que al darle a un link borre, sin más, simplemente haz esto:

Código PHP:
<a href="borrar.php?id=<?php echo $row["id_noticia"]; ?>">Borrar(o una imagen con una X)</a>

Y eso será el link el cual tenga ya el ?id=numero

Un saludo

Gracias Heli0s, he implementado el otro metodo, el que me ha pasado Vallu y funciona perfect.

Os dejo los codigos.

De todas maneras tu método me le guardo, por si cambio el boton Borrar por una Imagen.

editar.php
Código PHP:
<?
      
//recibimos la variable id enviada en el enlace por GET
      
$id=$_GET[id];
       include (
"conex.php");
      
//hacemos las consultas
      
$result=mysql_query("select * from noticias where id_noticia='$id'",$connect);
      
//Una vez seleccionados los registros los mostramos para su edición
      
while($row=mysql_fetch_array($result)) {
      echo 
"<form action=\"edit.php\" method=\"post\">
      <input type=\"hidden\" name=\"id\" value=\""
.$row[id_noticia]."\">
      <br>Título noticia:<br>
      <input type=\"text\" name=\"titulo\" value=\""
.$row[titulo]."\">
      <br>Autor:<br>
      <input type=\"text\" name=\"autor\" value=\""
.$row[autor]."\">
      <br>Categoría:<br>
      <input type=\"text\" name=\"categoria\" value=\""
.$row[categoria]."\">
      <br>Escriba el articulo<br>
      <textarea name=\"noticia\" cols=\"50\" rows=\"10\">\""
.$row[noticia]."\"</textarea>
      <br><input type=\"submit\" value=\"Editar\" > <input type=\"submit\" value=\"Restablecer\"> <br>
      </form>"
;
echo 
"<form action=\"borrar.php\" method=\"post\">
      <input type=\"hidden\" name=\"id\" value=\""
.$row[id_noticia]."\">
      <input type=\"submit\" value=\"Borrar\"><br>
      </form>"
;  
      }
      
mysql_free_result($result);
      
mysql_close($connect);
      
?>
borrar.php
Código PHP:
 <?
      
//recibimos la variable $id
      
$id=$_GET['id'];
      
$id=$_POST['id'];
    include (
"conex.php");
      
//borramos los registros pertenecientes a la id
      
mysql_query("delete from noticias where id_noticia='$id'",$connect);
      
header("location: ../index.php");
      
?>