Foro de elhacker.net

Programación => PHP => Mensaje iniciado por: jalbtercero en 20 Mayo 2016, 17:31 pm



Título: boton en php
Publicado por: jalbtercero en 20 Mayo 2016, 17:31 pm
Quiero que salga un boton para poder borrar el contenido de un <td> desde la base de datos, no me da error pero el boton no aparece.


Código
  1. <html>
  2. <head>
  3. <meta charset="UTF-9">
  4. <style>
  5. table {
  6. width: 100%;
  7. border-collapse: collapse;
  8. }
  9.  
  10. table, th {
  11. border: 1px solid black;
  12. padding: 5px;
  13.  
  14.  
  15. }
  16. td {
  17.        border: 1px solid black;
  18. padding: 5px;
  19.  
  20.  
  21. }
  22.  
  23. th {
  24.        background-color: #4CAF50;
  25.        color: white;
  26. text-align: left;
  27. }
  28. </style>
  29. <?php
  30.    if (isset($_POST['borrar_archivo'])) {
  31.    require("connect_db2.php");
  32.    if (mysqli_query($link, "DELETE FROM examenes WHERE asignatura = '{$_POST['archivo_id']}'")) {
  33.        echo "<p>Archivo borrado correctamente!</p>";
  34.        mysqli_close($link);
  35.  
  36.    } else {
  37.       echo "Error al conectar a base de datos";
  38. }
  39. }
  40. ?>
  41. </head>
  42. <body bgcolor="#8DC6FF">
  43. <?php
  44. require("connect_db2.php");
  45. $borrar_html =
  46.                "<form action='' method='post'>
  47.                    <input type='hidden' name='archivo_id' value='{$resultados['id']}'/>
  48.                    <button type='submit' name='borrar_archivo'>Borrar</button>
  49.                 </form>";
  50.  
  51. function mostrarDatos($resultados) {
  52. if($resultados !=NULL){
  53. echo
  54.            "<tr>
  55.        <td>{$resultados['asignatura']}</td>
  56.        <td>{$resultados['dia']}</td>
  57.                <td>{$resultados['descripcion']}</td>
  58.        <td>
  59.  
  60.                  $borrar_html
  61.  
  62.                </td>
  63.    </tr>";
  64. } else {
  65.  
  66. echo "<br/>No hay mas datos<br/>";
  67. }
  68. }
  69.  
  70.  
  71. $result = mysqli_query($link,"SELECT * FROM examenes");
  72. echo "<table>
  73. <tr>
  74. <th>Asignatura</th>
  75. <th>Dia</th>
  76. <th>Descripcion</th>
  77.                <th>Accion</th>
  78. </tr>";
  79. while($fila = mysqli_fetch_array($result)) {
  80. mostrarDatos($fila);
  81. }
  82. mysqli_close($link);
  83. ?>
  84. </body>
  85. </html>
  86.