Modificar registros mysql con php

Tengo este código el cual me muestra la lista de registros, al dar clic en el lápiz me manda a una pantalla, con el id correspondiente pero no logro crear un formulario con el que pueda modificar los campos, Ayuda por favor!

<! DOCTYPE html>

<body>
<br>
<div class="row table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>Nombre</th>
<th>Apellido</th>
<th>Acción</th>
<th>Tiempo</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php while($row =$resultado->fetch_array(MYSQL_ASSOC)) { ?>
<tr>
<td><?php echo $row ['id'];?></td>
<td><?php echo $row ['firstname'];?></td>
<td><?php echo $row ['lastname'];?></td>
<td><?php echo $row ['action'];?></td>
<td><?php echo $row ['fecha'];?></td>
<td><a href="modificarse.php?id=<?php echo $row ['id'];?>"><img src="img/lapiz.png""></span></a></td>

</tr>
<?php }?>
</tbody>
</table>
</div>

</body>
</html>

1 Respuesta

Respuesta
1

En el fichero modificarse.php debes leer mediante una consulta SELECT de SQL el registro con el id que le has pasado. Recuerda que el id lo has pasado como información de tipo GET por lo tanto la consulta podría similar a:

SELECT * FROM tabla WHERE id = $_GET['id'];

Una vez leído este registro, creas un fomulario HTML y rellenas cada input con los valores del registro. Ejemplo:

<input type="text" name="firstname" value="<?php echo $row ['firstname']; ?> />

Por último cuando el usuario confirme el envío actualizas el registro con el ID y una consulta UPDATE.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas