So, the question is let $X$ be a Hausdorff space such that each point of X has a neighborhood that is homeomorphic with an open subset of $\mathbb{R}^{m}$. Show that if $X$ is compact, then $X$ is an $m$-manifold. It's from Munkres' Topology book(section 36). Here is my flawed proof(but I can't see where my mistake is)
Proof: Let $U$ be an open set of $X$. Let $x$ (where $x \in U$) and let $V$ be the neighborhood of $x$ that is homeomorphic to an open subset of $\mathbb{R}^{m}$. So, we consider $W = U \cap V$. This is an open set in $V$, so it is homeomorphic to an open subset P of $\mathbb{R}^{m}$. Let f be the homeomorphism. Since, $\mathbb{R}^{m}$is second countable, there exists a basis element $B$ such that $f(x) \in B \subset P$. So, $x\in f^{-1}(B) \subset W \subset U$. $f^{-1}(B)$ is obviously open by continuity. Since, $\mathbb{R}^{m}$ is second countable, if we repeat this procedure for each open set $U$ of $X$, the collection $f^{-1}(B)$ is going to be countable as well and is a basis. Hence, X is second countable and a manifold. $\hspace{70mm}$ $\square$
I know my proof is wrong because I didn't use the compactness condition at all. Could someone point out where exactly my proof goes astray and maybe also give a hint towards a correct proof?
By compactness you get a finite open cover $U_1,\ldots, U_k$ of $X$ such that each $U_i$ is homeomorphic to an open subset of $\mathbb R^n$. Thus for each $U_i$ you get a countable family $\mathcal B_i$ of open $B_{i,n} \subset U_i$ such that each open subset of $U_i$ is a union of elements of $\mathcal B_i$. Let $\mathcal B = \bigcup_{i=1}^k \mathcal B_i$. This is a countable set and it is a basis for $X$. To see that, let $V \subset X$ be open. Then the $V_i = V \cap U_i$ are open subsets of $U_i$ and their unon is $V$. Each $V_i$ is a union of elements of $\mathcal B_i$, thus $V$ is a union of elements of $\mathcal B$.
Remark: It would be sufficient to assume that each open cover of $X$ has a countable subcover. Such spaces $X$ are known a Lindelöf.