Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General »

Borrar datos mysql

Estas en el tema de Borrar datos mysql en el foro de Bases de Datos General en Foros del Web. Buenas gente soy kimizombie tengo una duda, actualmente estoy haciendo un sistema de comentarios en el cual quiero que se pueda borrar el comentario que ...
  #1 (permalink)  
Antiguo 06/07/2010, 10:37
 
Fecha de Ingreso: marzo-2009
Mensajes: 8
Antigüedad: 15 años, 1 mes
Puntos: 1
Borrar datos mysql

Buenas gente soy kimizombie tengo una duda, actualmente estoy haciendo un sistema de comentarios en el cual quiero que se pueda borrar el comentario que yo quiera dadoq ue la insercion de datos y mostrado de datos me sale de forma satisfactoria
http://www.kimizombie.comeze.com/comentarios/comentario.html
Lo que quiero es que en la columna borrar me aparezca un boton borrar y cuando de click sobre el me elimine el comentario que sea. dejo aqui el codigo completo:

Código PHP:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Comentario</title>
<style type="text/css">
<!--
.header {
    font-family: Georgia, "Times New Roman", Times, serif;
    font-size: 36px;
    color: #00F;
    font-weight: bold;
    text-align: center;
}
.copy {
    font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
    font-size: 10px;
    color: #000;
}
-->
</style>
</head>

<body>
<table width="100%" height="100%" border="8">
  <tr>
    <td height="70" colspan="2" bgcolor="#009999" class="header">SISTEMA DE COMENTARIOS V1.0</td>
  </tr>
  <tr>
    <td height="100%" colspan="2" valign="top" bgcolor="#CCCCCC"><p><br>
<?
include 'connect_db.php';
//Asignamos las variables para el metodo post
$nombre $_POST['nombre'];
$tema $_POST['tema'];
$texto $_POST['texto'];

if (
$nombre==NULL) {
echo 
"<script type=\"text/javascript\">window.alert(\"Inserte un nombre\");</script>"
}
if (
$tema==NULL) {
echo 
"<script type=\"text/javascript\">window.alert(\"Inserte un tema\");</script>"
}
if (
$texto==NULL) {
echo 
"<script type=\"text/javascript\">window.alert(\"Inserte un texto\");</script>"
}
else {
    
//INSERTAMOS LOS REGISTROS
    
$query "INSERT INTO comentarios (nombre, tema, texto) VALUES('$nombre','$tema','$texto')";
     
mysql_query($query) or die(mysql_error());
     }
?>
<h1>
  <div align="center">Lectura de comentarios</div></h1>
<?
    $result
=mysql_query("select * from comentarios");
?>
<table width="100%" height="77" border="8" align="center">
<tr>
<th width="20%" height="40"><div align="left">NOMBRE</div></th>
<th width="20%" height="40"><div align="left">TEMA</div></th>
<th width="40%" height="40"><div align="left">TEXTO</div></th>
<th width="10%" height="40"><div align="left">BORRAR</div></th>

</tr><div align="left">TEXTO</div>
<?
//Mostramos los registros
while ($row=mysql_fetch_array($result))
{
echo 
'<tr><td>'.$row["nombre"].'</td>';
echo 
'<td>'.$row["tema"].'</td>';
echo 
'<td>'.$row["texto"].'</td>';
printf("<tr><td> &nbsp;%s </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td><td> &nbsp;%s&nbsp; </td></td><td> <a href=\"borra.php?id=%d\"> Borra </a></td></tr>"$row["nombre"], $row["tema"], $row["texto"],$row["id"]);
}
mysql_free_result($result)
?>

</table></p>

</select>
<br>
<INPUT TYPE="SUBMIT" value="Borrar">
</FORM>
</div>
<p>&nbsp;</p></td>
  </tr>
  <tr>
    <td width="19%" height="30" bgcolor="#CCCCCC" class="copy">Realizado por: José Antonio de la Torre  </td>
    <td width="81%" bgcolor="#CCCCCC" class="copy">Http://kimizombie.webs.com</td>
  </tr>
</table>
</body>
</html>
Muchas gracias de antemano quiero algo parecido a esto:
http://www.webestilo.com/php/ejem/ejem07e.phtml

el codigo que pone en esa web es este:

http://www.webestilo.com/php/php07e.phtml

pero no consigo entender el tema de la id y como llevarla etc si me podeis ayudar un poco a entenderlo y crear el script de borrado os estaria muy agradecido
  #2 (permalink)  
Antiguo 06/07/2010, 10:58
 
Fecha de Ingreso: marzo-2009
Mensajes: 8
Antigüedad: 15 años, 1 mes
Puntos: 1
Respuesta: Borrar datos mysql

Ya se puede cerrar el tema ya lo he implantado bien =)

Código PHP:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Comentario</title>
<style type="text/css">
<!--
.header {
    font-family: Georgia, "Times New Roman", Times, serif;
    font-size: 36px;
    color: #00F;
    font-weight: bold;
    text-align: center;
}
.copy {
    font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
    font-size: 10px;
    color: #000;
}
-->
</style>
</head>

<body>
<table width="100%" height="100%" border="8">
  <tr>
    <td height="70" colspan="2" bgcolor="#009999" class="header">SISTEMA DE COMENTARIOS V1.0</td>
  </tr>
  <tr>
    <td height="100%" colspan="2" valign="top" bgcolor="#CCCCCC"><p><br>
<?
include 'connect_db.php';
//Asignamos las variables para el metodo post
$nombre $_POST['nombre'];
$tema $_POST['tema'];
$texto $_POST['texto'];

if (
$nombre==NULL) {
echo 
"<script type=\"text/javascript\">window.alert(\"Inserte un nombre\");</script>"
}
if (
$tema==NULL) {
echo 
"<script type=\"text/javascript\">window.alert(\"Inserte un tema\");</script>"
}
if (
$texto==NULL) {
echo 
"<script type=\"text/javascript\">window.alert(\"Inserte un texto\");</script>"
}
else {
    
//INSERTAMOS LOS REGISTROS
    
$query "INSERT INTO comentarios (nombre, tema, texto) VALUES('$nombre','$tema','$texto')";
     
mysql_query($query) or die(mysql_error());
     }
?>
<h1>
  <div align="center">Lectura de comentarios</div></h1>
<?
    $result
=mysql_query("select * from comentarios");
?>
<table width="100%" height="77" border="8" align="center">
<tr>
<th width="20%" height="40"><div align="left">NOMBRE</div></th>
<th width="20%" height="40"><div align="left">TEMA</div></th>
<th width="40%" height="40"><div align="left">TEXTO</div></th>
<th width="10%" height="40"><div align="left">BORRAR</div></th>

<?php      
   
while($row mysql_fetch_array($result)) {
      
printf("<tr><td>&nbsp;%s</td><td>&nbsp;%s&nbsp;</td><td>&nbsp;%s&nbsp;</td><td><a href=\"borra.php?id=%d\">Borra</a></td></tr>"$row["nombre"],$row["tema"],$row["texto"],$row["id"]);
   }
   
mysql_free_result($result);
?>

</table></p>

</select>
<br>
<INPUT TYPE="SUBMIT" value="Borrar">
</FORM>
</div>
<p>&nbsp;</p></td>
  </tr>
  <tr>
    <td width="19%" height="30" bgcolor="#CCCCCC" class="copy">Realizado por: José Antonio de la Torre  </td>
    <td width="81%" bgcolor="#CCCCCC" class="copy">Http://kimizombie.webs.com</td>
  </tr>
</table>
</body>
</html>
BORRA.PHP
Código PHP:
<?php
   
include("connect_db.php");
   
$id=$_GET['id'];
   
mysql_query("delete from comentarios where id = $id");
   
   
header("Location: muestra.php");
?>

Etiquetas: borrar, mysql
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 11:59.