-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgestion_usuarios.php
More file actions
31 lines (26 loc) · 1.03 KB
/
Copy pathgestion_usuarios.php
File metadata and controls
31 lines (26 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
require_once 'conexiones/conexion.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add_user'])) {
// Obtener los datos del formulario
$email = $_POST['email'];
$password = $_POST['password'];
$role = $_POST['role'];
// Validar que los campos no estén vacíos
if (empty($email) || empty($password) || empty($role)) {
$error = "Todos los campos son obligatorios.";
} else {
try {
// Encriptar la contraseña
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
// Insertar el nuevo usuario en la base de datos
$stmt = $pdo->prepare("INSERT INTO usuarios (email, password, role, created_at) VALUES (?, ?, ?, NOW())");
$stmt->execute([$email, $hashed_password, $role]);
// Redirigir o mostrar un mensaje de éxito
header('Location: usuarios.php');
exit;
} catch (PDOException $e) {
$error = "Error al agregar el usuario: " . $e->getMessage();
}
}
}
?>