Advertisement
yagami07

editar

Feb 25th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title></title>
  4. </head>
  5. <body>
  6. <center>
  7. <h1> .: Editar Persona :. </h1>
  8. <hr>
  9. <a href="../">Home</a> |
  10. <a href="index.php">Atrás</a>
  11. <hr>
  12.  
  13. <?php
  14. // Conectar con el servidor y seleccioné a bd
  15. $con = new mysqli('localhost', 'root', '', 'adsi120_121');
  16.  
  17. if ($_POST) {
  18.  
  19. $id = $_POST['id'];
  20. $nom = $_POST['nom'];
  21. $dir = $_POST['dir'];
  22. $tel = $_POST['tel'];
  23. $ema = $_POST['ema'];
  24. $fec = $_POST['fec'];
  25. $ciudadlol = $_POST['ciu'];
  26.  
  27. $sql = "UPDATE Personas SET nombre='$nom',
  28. direccion='$dir', telefono='$tel',
  29. email='$ema', fecha_nacimiento='$fec', id_ciudad='$ciudadlol'
  30. WHERE id = '$id'";
  31.  
  32. $resultado = $con->query($sql);
  33.  
  34. if ($resultado) {
  35. header('location: index.php');
  36. }else{
  37. echo "Error!";
  38. }
  39. }
  40.  
  41. $id = $_GET['id'];
  42.  
  43. // Creando la consulta
  44. $sql = "SELECT * FROM Personas WHERE id = $id";
  45.  
  46. // ejecutando la consulta
  47. $resultado = $con->query($sql);
  48.  
  49. $persona = $resultado->fetch_assoc();
  50.  
  51. ?>
  52.  
  53. <form method="POST">
  54. <input required name="id" placeholder="ID" value="<?php echo $persona['id'] ?>" readonly><br><br>
  55. <input required name="nom" placeholder="Nombre" value="<?php echo $persona['nombre'] ?>"><br><br>
  56. <input required name="dir" placeholder="Direccion" value="<?php echo $persona['direccion'] ?>"><br><br>
  57. <input required type="number" name="tel" placeholder="Telefono" value="<?php echo $persona['telefono'] ?>"><br><br>
  58. <input required type="email" name="ema" placeholder="E-mail" value="<?php echo $persona['email'] ?>"><br><br>
  59. <input required type="date" name="fec" placeholder="Fecha de Nacimiento" value="<?php echo $persona['fecha_nacimiento'] ?>"><br><br>
  60.  
  61. <select name="ciu" required>
  62. <?php
  63. $sql = "SELECT * FROM ciudades";
  64. $resultado = $con->query($sql);
  65. while ($ciudad = mysqli_fetch_assoc($resultado)) {
  66. if ($persona['id_ciudad'] == $ciudad['id'])
  67. echo "<option value='{$ciudad['id']}' selected>{$ciudad['nombre']}</option>";
  68. else
  69. echo "<option value='{$ciudad['id']}'>{$ciudad['nombre']}</option>";
  70. }
  71.  
  72. ?>
  73. </select><br><br>
  74.  
  75. <input type="submit">
  76. </form>
  77.  
  78. </center>
  79. </body>
  80. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement