<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> tabla</title>
</head>
<body>
<center>
<center> <table border="1">
<thead>
<tr>
<th colspan="1"> <a href="index.html">nuevo</a></th>
<th colspan="5"> lista de alumnos</th>
</tr>
</thead>
<tbody>
<tr>
<td> id </td>
<td> nombre</td>
<td> grado </td>
<td> edad</td>
<td> Modificar</td>
<td> Eliminar</td>
</tr>
<?php
include("conexion.php");
$query="SELECT * FROM alumnos ORDER BY 1";
$resultado=$conexion->query($query);
while($row=$resultado->fetch_assoc()){ //ciclo para llamar datos en pantalla
?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['nombre'];?></td>
<td><?php echo $row['grado'];?></td>
<td><?php echo $row['edad'];?></td>
<td><a href="modificar.php ?id=<?php echo $row['id'];?>">modificar</a></td>
<td><a href="eliminar.php ?id=<?php echo $row['id'];?>">eliminar</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
</center>
</body>
</html>
___________________________________________________________________________
modificar datos
<!DOCTYPE html>
<html>
<head>
<title>guardar</title>
</head>
<body>
<center>
<?php
$id=$_REQUEST['id'];
include("conexion.php");
$query="SELECT *FROM alumnos WHERE id='$id'";
$resultado=$conexion->query($query);
$row=$resultado->fetch_assoc();
?>
<form action="operacionmodificar.php?id=<?php echo $row['id'];?>" method="POST">
<CENTER><table border=2 width=400 align=center>
<tr>
<td>nombre</td>
<td> <input type="text" required name="nombre" size=44px placeholder="ingrese el nombre" value="<?php echo $row['nombre'];?>"/> </td>
</tr>
<tr>
<td>grado</td>
<td> <input type="text" required name="grado" placeholder="ingrese el grado academico" value="<?php echo $row['grado'];?>"/> </td>
</tr>
<tr>
<td>edad</td>
<td> <input type="text" required name="edad" placeholder="ingrese la edad de la persona" value="<?php echo $row['edad'];?>"/></td>
</tr>
<tr>
<td colspan=2 align="center">
<button type="submit">GUARDAR CAMBIOS</button>
</td>
</tr>
</table>
</FORM>
</CENTER>
</BODY>
</HTML>
____________________
modificar datos siempre
<?php
include("conexion.php");
$id=$_REQUEST['id'];
$nombre= $_POST['nombre'];
$grado= $_POST['grado'];
$edad= $_POST['edad'];
$query="UPDATE alumnos SET nombre='$nombre', grado='$grado', edad='$edad' WHERE id='$id' ";
$resultado= $conexion->query($query);
if($resultado){
header("Location: tabla.php");
}
else
{
echo"error al insertar dato";
}
?>
_______________________________
eliminar datos
<?php
include("conexion.php");
$id=$_REQUEST['id'];
$query="DELETE FROM alumnos WHERE id='$id'";
$resultado=$conexion->query($query);
if($resultado){
header("Location: tabla.php");
}
else
{
echo"error al eliminar datos";
}
?>
No hay comentarios:
Publicar un comentario