Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
require 'config.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
// Check of de gebruikersnaam al bestaat
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->execute(['username' => $username]);
if ($stmt->rowCount() > 0) {
$error = "Gebruikersnaam bestaat al!";
} else {
// Nieuwe gebruiker invoegen
$stmt = $pdo->prepare("INSERT INTO users (username, password) VALUES (:username, :password)");
$stmt->execute(['username' => $username, 'password' => $password]);
header('Location: login.php');
exit();
}
}
?>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registreren</title>
<link rel="stylesheet" href="styles.css">
</head>
<body class="login-page">
<div class="login-container">
<h2>Registreren</h2>
<?php if (isset($error)): ?>
<div class="error"><?php echo $error; ?></div>
<?php endif; ?>
<form action="register.php" method="POST">
<input type="text" name="username" placeholder="Gebruikersnaam" required>
<input type="password" name="password" placeholder="Wachtwoord" required>
<button type="submit">Registreer</button>
</form>
<p>Al een account? <a href="login.php">Log hier in</a></p>
</div>
</body>
</html>