Ver Mensaje Individual
  #15 (permalink)  
Antiguo 01/02/2015, 17:51
Drekazo
 
Fecha de Ingreso: enero-2015
Mensajes: 9
Antigüedad: 9 años, 2 meses
Puntos: 0
Respuesta: Eliminar registro tabla

mostrardatos.php:


Código PHP:
Ver original
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5.  
  6. <link rel="stylesheet" type="text/css" href="css.css">
  7. <title></title>
  8. </head>
  9. <body>
  10. <div id="mediodatos">
  11. <?php
  12.  
  13. //para hacer la conexion con mysql
  14. $host="localhost";
  15. $user="root";
  16. $pass="";
  17. $bd="miempresa";
  18.  
  19. require("borra.php");
  20.  
  21. $nombre = isset($_POST['nombre']) ? $_POST['nombre'] : null ;
  22.  $apellidos =  isset($_POST['apellidos']) ? $_POST['apellidos'] : null ;
  23.  $fecha = isset($_POST['fecha']) ? $_POST['fecha'] : null ;
  24.  $nif = isset($_POST['nif']) ? $_POST['nif'] : null ;
  25.  $provincia = isset($_POST['provincia']) ? $_POST['provincia'] : null ;
  26.  
  27. //aqui la conexion con la BD e inserta datos del formulario
  28. $conex = mysqli_connect($host,$user,$pass,$bd);
  29.     if(!$conex){
  30.             echo "ERROR".mysqli_connect_error();
  31.            
  32.             }
  33. $sql = "INSERT INTO usuaris (nif, nom, cognoms, data_naix, provincia) VALUES ('$nif', '$nombre','$apellidos','$fecha','$provincia')";
  34.     if(!$sql){
  35.             echo "ERROR en la ejecucion de la sentencia".mysqli_connect_error();
  36.     }
  37. mysqli_query($conex,$sql);
  38.  
  39. $cadena="Select nif,nom,cognoms,data_naix,provincia from usuaris";
  40. $result=mysqli_query($conex,$cadena);
  41.         echo "<table id='miTabla' border=1  style='text-align: left; margin: auto;'>";
  42.         echo"<th><i>Nif</i></th><th><i>Nom</i></th><th><i>Cognoms</i></th><th><i>Data</i></th><th><i>Provincia</i></th>";
  43.         while($row=mysqli_fetch_array($result)) {
  44.                 echo( "<tr>
  45.                     <td>".$row['nif']."</td>
  46.                     <td>".$row['nom']."</td>
  47.                     <td>".$row['cognoms']."</td>
  48.                     <td>".$row['data_naix']."</td>
  49.                     <td>".$row['provincia']."</td>
  50.                     <td>Editar</td>
  51.                    
  52.                     <td><a href='borra.php?nif=".$row['nif']."'>Eliminar</a></td>;
  53.                 </tr>");   
  54.              }
  55.            
  56.          echo "</table>";  
  57. mysqli_close($conex);
  58.  
  59. ?><br>
  60.  
  61. <input type="button2" value="Volver" onClick="location.href='formulmysql.php'"class="boton2" />
  62. </div>
  63. </body>
  64. </html>

borrar.php:

Código PHP:
Ver original
  1. <?php
  2.  
  3. $host="localhost";
  4. $user="root";
  5. $pass="";
  6. $bd="miempresa";
  7.  
  8.  $conex = mysqli_connect($host,$user,$pass,$bd);
  9. $nif = $_GET['nif'];
  10. if(isset($nif)) {
  11.     $eliminar="DELETE FROM usuaris WHERE nif = '$nif'";
  12.     $result = mysqli_query($eliminar, $conex);
  13.     header ('Location: mostrardatos.php');
  14.  
  15.     }else {
  16.         echo"Error: " . mysqli_connect_error();
  17.         }
  18. ?>
creo que podria venir el problema a raiz del if