UNIVERSIDAD ABIERTA PARA ADULTOS
UAPA
Tema:
Desarrollo de Aplicaciones Web
FACILITADOR
Joan Tejada Caba
Participante:
Juan Jose Reyes Guzmán
Matricula:
09-0416
Fecha:
13-06-20
1- Crea una base de datos (Mysql o SqlServer
Nueva base de datos
(tarea5)
2- Elabora una tabla de empleados.
Tabla empleados
3- Crea un archivo php que conecte la base de datos, insertar
registro a la tabla, actualizar y consultar.
Insertar
<!DOCTYPE>
<html>
<head>
<title>Empleado</title>
</head>
<body>
<form action="Registro.php" method="POST">
Nombre: <input type="text" name="txtNombre"> <br/>
Apellido: <input type="text" name="txtApellido"> <br/>
Telefono: <input type="text" name="txtTelefono"> <br/>
Cedula: <input type="text" name="txtCedula"> <br/>
<input type="submit" value="Registrar" name="btnRegistrar">
</form>
</body>
</html>
<!DOCTYPE>
<html>
<head>
<title>Registrar</title>
</head>
<body>
<?php
$server = "localhost";
$usuario = "root";
$contraseña = "";
$bd = "tarea5";
$conexion = mysqli_connect($server,$usuario,$contraseña,$bd) or die ("error
en la conexion");
$nombre= $_POST['txtNombre'];
$apellido= $_POST['txtApellido'];
$telefono= $_POST['txtTelefono'];
$cedula= $_POST['txtCedula'];
$insertar = "INSERT into empleados values
('$nombre','$apellido','$telefono','$cedula')";
$resultado = mysqli_query($conexion,$insertar) or die ("error al guardar los
registros");
mysqli_close($conexion);
echo "Datos ingresados correctamente";
?>
</body>
</html>
Actualizar
<!DOCTYPE>
<html>
<head>
<title>Empleado</title>
</head>
<body>
<form action="Actualiza.php" method="POST">
Nombre: <input type="text" name="txtNombre"> <br/>
Apellido: <input type="text" name="txtApellido"> <br/>
Telefono: <input type="text" name="txtTelefono"> <br/>
Cedula: <input type="text" name="txtCedula"> <br/>
<input type="submit" value="Actualizar" name="btnActualizar">
</form>
</body>
</html>
<!DOCTYPE>
<html>
<head>
<title>Actualizando</title>
</head>
<body>
<?php
$server = "localhost";
$usuario = "root";
$contraseña = "";
$bd = "tarea5";
$conexion = mysqli_connect($server,$usuario,$contraseña,$bd) or die ("error
en la conexion");
$nombre= $_POST['txtNombre'];
$apellido= $_POST['txtApellido'];
$telefono= $_POST['txtTelefono'];
$cedula= $_POST['txtCedula'];
mysqli_query($conexion,"UPDATE empleados set nombre='$nombre'") or die
("error al Actualizar los registros");
mysqli_close($conexion);
echo "Datos Actualizados correctamente";
?>
</body>
</html>
Consultar
<?php
$con = new mysqli("localhost", "root", "","tarea5");
$datos = $con->query("SELECT * FROM empleados")
?>
<table border="1px">
<thead>
<th>Nombre</th>
<th>Apellido</th>
<th>Telefono</th>
<th>Cedula</th>
</thead>
<tbody>
<?php while($user = mysqli_fetch_array ($datos)){?>
<tr>
<td><?php echo $user['nombre']; ?></td>
<td><?php echo $user['apellido']; ?></td>
<td><?php echo $user['telefono']; ?></td>
<td><?php echo $user['cedula']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>