prepare("SELECT id FROM users WHERE email = ?"); $stmt->execute([$email]); if ($stmt->fetch()) { $error = 'Email sudah terdaftar.'; } else { // Hash the password $hashed_password = password_hash($password, PASSWORD_DEFAULT); // Insert new user $stmt = $pdo->prepare("INSERT INTO users (name, email, password, role) VALUES (?, ?, ?, ?)"); if ($stmt->execute([$name, $email, $hashed_password, $role])) { $_SESSION['success_message'] = "Registrasi berhasil! Silakan login."; header("Location: login.php"); exit; } else { $error = 'Terjadi kesalahan. Gagal mendaftar.'; } } } catch (PDOException $e) { // In production, you should log this error instead of showing it to the user. $error = "Database error: " . $e->getMessage(); } } } ?>
Buat akun baru untuk memulai.