prepare("SELECT id FROM users WHERE username = ?"); $stmt->execute([$username]); if ($stmt->fetch()) { $error = "Username already exists. Please choose another one."; } else { // Get 'teacher' role ID $stmt = $pdo->prepare("SELECT id FROM roles WHERE role_name = 'teacher'"); $stmt->execute(); $role = $stmt->fetch(PDO::FETCH_ASSOC); if (!$role) { // This is a fallback, 'teacher' role should exist from auth.php $error = "Default role 'teacher' not found. Please contact admin."; } else { $role_id = $role['id']; $password_hash = password_hash($password, PASSWORD_BCRYPT); $sql = "INSERT INTO users (username, password_hash, role_id) VALUES (?, ?, ?)"; $stmt= $pdo->prepare($sql); if ($stmt->execute([$username, $password_hash, $role_id])) { $_SESSION['success_message'] = "Registration successful! You can now login."; header("Location: login.php"); exit(); } else { $error = "Something went wrong. Please try again later."; } } } } } ?> Sign Up - Bhuddi School
Sign Up