FSCash/html/admin.php
2026-01-04 23:04:09 +01:00

71 lines
2.4 KiB
PHP

<?php
// Datenbankverbindung
require 'config.php';
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $dbuser, $dbpass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
die("Datenbankverbindung fehlgeschlagen: " . $e->getMessage());
}
// Wenn das Formular abgesendet wurde
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
if (!empty($username) && !empty($password)) {
$hash = password_hash($password, PASSWORD_DEFAULT);
try {
$stmt = $pdo->prepare("INSERT INTO users (username, password) VALUES (?, ?)");
$stmt->execute([$username, $hash]);
$success = "Benutzer '$username' wurde erfolgreich angelegt.";
} catch (PDOException $e) {
$error = "Fehler beim Anlegen des Benutzers: " . $e->getMessage();
}
} else {
$error = "Bitte Benutzername und Passwort eingeben.";
}
}
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin: Benutzer anlegen</title>
<style>
body { font-family: Arial, sans-serif; max-width: 500px; margin: 0 auto; padding: 20px; }
.form-group { margin-bottom: 15px; }
label { display: block; margin-bottom: 5px; }
input[type="text"], input[type="password"] { width: 100%; padding: 8px; }
button { padding: 10px 15px; background: #007bff; color: white; border: none; cursor: pointer; }
.success { color: green; }
.error { color: red; }
</style>
</head>
<body>
<h1>Benutzer anlegen</h1>
<?php if (isset($success)): ?>
<p class="success"><?php echo htmlspecialchars($success); ?></p>
<?php endif; ?>
<?php if (isset($error)): ?>
<p class="error"><?php echo htmlspecialchars($error); ?></p>
<?php endif; ?>
<form method="post">
<div class="form-group">
<label for="username">Benutzername:</label>
<input type="text" id="username" name="username" required>
</div>
<div class="form-group">
<label for="password">Passwort:</label>
<input type="password" id="password" name="password" required>
</div>
<button type="submit">Benutzer anlegen</button>
</form>
</body>
</html>