List users from database

This commit is contained in:
coolneng 2020-06-16 22:50:35 +02:00
parent bb1b2f077b
commit 29c6d7bb6d
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
6 changed files with 109 additions and 71 deletions

View File

@ -5,6 +5,5 @@ This project consists of an Information System for a Medical Institution.
** Technologies ** Technologies
- PHP - PHP
- MariaDB - Javascript (AJAX)
- Nginx - MySQL
- Docker

View File

@ -1,52 +0,0 @@
<!doctype html>
<html class="no-js" lang="es">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Gestión de usuarios</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<!-- Place favicon.ico in the root directory -->
<link rel="stylesheet" href="static/style.css" type="text/css" media="screen" />
</head>
<body>
<!--[if lt IE 8]>
<p class="browserupgrade">
You are using an <strong>outdated</strong> browser. Please
<a href="http://browsehappy.com/">upgrade your browser</a> to improve
your experience.
</p>
<![endif]-->
<form method="post" action="../src/user_management.php">
<div class="input-group">
<label>Nombre</label>
<input type="text" name="nombre" value="">
</div>
<div class="input-group">
<label>usuario</label>
<input type="text" name="usuario" value="">
</div>
<div class="input-group">
<label>contraseña</label>
<input type="password" name="contraseña" value="">
</div>
<div class="select-input">
<label>rol</label>
<select id="rol" name="rol">
<option value="1">administrativo</option>
<option value="2">médico</option>
</select>
</div>
<div class="input-group">
<label>correo</label>
<input type="text" name="correo" value="">
</div>
<div class="input-group">
<button class="btn" type="submit" name="submit" >Guardar</button>
</div>
</form>
</body>
</html>

View File

@ -13,7 +13,7 @@ function closeDatabase($pdo) {
} }
function displayResults($query) { function displayResults($query) {
while($row = $query->fetch()){ foreach($query->fetch(PDO::FETCH_ASSOC) as $row){
echo $row . "\n"; echo $row . "\n";
} }
} }
@ -96,4 +96,18 @@ function listAppointments($pdo, string $doctor) {
findRows($pdo, "cita", "medico", $doctor); findRows($pdo, "cita", "medico", $doctor);
} }
function displayUsers($query) {
foreach($query->fetch(PDO::FETCH_ASSOC) as $row){
echo $row["nombre"];
}
}
function listUsers($pdo) {
$query = "SELECT usuario.nombre, usuario.usuario, rol.nombre, usuario.correo FROM usuario
INNER JOIN rol ON usuario.rol = rol.codigo";
$result = $pdo->query($query)->fetchAll();
return $result;
}
?> ?>

79
src/user.php Normal file
View File

@ -0,0 +1,79 @@
<!doctype html>
<html class="no-js" lang="es">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Gestión de usuarios</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../static/style.css" type="text/css" media="screen" />
</head>
<body>
<!--[if lt IE 8]>
<p class="browserupgrade">
You are using an <strong>outdated</strong> browser. Please
<a href="http://browsehappy.com/">upgrade your browser</a> to improve
your experience.
</p>
<![endif]-->
<table>
<thead>
<tr>
<th>Nombre</th>
<th>Usuario</th>
<th>Rol</th>
<th>Correo</th>
<th colspan="2">Acciones</th>
</tr>
</thead>
<?php
include 'database.php';
$pdo = connectDatabase("practica", "practica", "practica");
$list = listUsers($pdo);
foreach($list as $row) :
?>
<tr>
<td><?php echo $row[0]; ?></td>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[3]; ?></td>
<td>
<a href="index.php?edit=" class="edit_btn" >Editar</a>
</td>
<td>
<a href="server.php?del=" class="del_btn">Borrar</a>
</td>
</tr>
<?php endforeach ?>
</table>
<form method="post" action="user_management.php">
<div class="input-group">
<label>Nombre</label>
<input type="text" name="nombre" value="">
</div>
<div class="input-group">
<label>usuario</label>
<input type="text" name="usuario" value="">
</div>
<div class="input-group">
<label>contraseña</label>
<input type="password" name="contraseña" value="">
</div>
<div class="select-input">
<label>rol</label>
<select id="rol" name="rol">
<option value="1">administrativo</option>
<option value="2">médico</option>
</select>
</div>
<div class="input-group">
<label>correo</label>
<input type="text" name="correo" value="">
</div>
<div class="input-group">
<button class="btn" type="submit" name="submit" >Guardar</button>
</div>
</form>
</body>
</html>

View File

@ -1,8 +1,16 @@
<?php <?php
include'database.php'; include'database.php';
if (isset($_POST['submit'])) {
$data = $_POST; function userCreation(){
$pdo = connectDatabase("practica", "practica", "practica"); $data = $_POST;
createUser($pdo, $data); $pdo = connectDatabase("practica", "practica", "practica");
closeDatabase($pdo); $message = createUser($pdo, $data);
closeDatabase($pdo);
$_SESSION['message'] = $message;
header('location: user.php');
}
if (isset($_POST['submit'])) {
userCreation();
} }

View File

@ -69,13 +69,3 @@ form {
border-radius: 3px; border-radius: 3px;
background: #800000; background: #800000;
} }
.msg {
margin: 30px auto;
padding: 10px;
border-radius: 5px;
color: #3c763d;
background: #dff0d8;
border: 1px solid #3c763d;
width: 50%;
text-align: center;
}