Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
CREATE TABLE IF NOT EXISTS usuarios (
clave VARCHAR(20) PRIMARY KEY,
usuario VARCHAR(50) NOT NULL
);
INSERT IGNORE INTO usuarios (clave, usuario)
VALUES ('12345', 'admin');
<?php
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$usuario = $_POST['usuario'] ?? '';
$clave = $_POST['clave'] ?? '';
$stmt = $pdo->prepare('SELECT * FROM usuarios WHERE usuario = :usuario AND clave = :clave');
$stmt->execute(compact('usuario', 'clave'));
if ($stmt->fetch()) {
echo "<h1>Bienvenido, has ingresado correctamente a Ferroalex!</h1>";
exit;
} else {
$error = 'Usuario o clave incorrectos';
}
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Login Ferroalex</title>
</head>
<body>
<h2>Login Ferroalex</h2>
<?php if ($error): ?>
<p style="color:red;"><?= htmlspecialchars($error) ?></p>
<?php endif; ?>
<form method="post">
Usuario: <input name="usuario" required><br>
Clave: <input name="clave" type="password" required><br>
<button type="submit">Ingresar</button>
</form>
</body>
</html>