prepare("SELECT id FROM team_members WHERE email = :email"); $stmt->bindParam(':email', $email); $stmt->execute(); if ($stmt->fetch()) { $message = 'A member with this email address already exists.'; } else { // Insert new member $sql = "INSERT INTO team_members (name, email, role) VALUES (:name, :email, :role)"; $stmt = $db->prepare($sql); $stmt->bindParam(':name', $name); $stmt->bindParam(':email', $email); $stmt->bindParam(':role', $role); if ($stmt->execute()) { $status = 'success'; $message = 'New team member added successfully!'; } else { $message = 'Failed to add new member. Please try again.'; } } } catch (PDOException $e) { // In a real app, log the error instead of showing it to the user // error_log($e->getMessage()); $message = 'Database error. Could not add member.'; } } } else { $message = 'Invalid request method.'; } header('Location: team.php?status=' . $status . '&msg=' . urlencode($message)); exit();