differential equations. exact

What conditions must be satisfied for $f(x)g(y)dx + h(x)p(y)dy = 0$ to be exact?

I found it is exact when $f(x)g'(y) = h'(x)p(y)$ but can I assume that $h(x) = \int f(x)\mathrm{d}x + c$ and $g(y) = \int p(y)\mathrm{d}y + c$?

-

Let the OP is exact. So we have $f(x)g'(y)=h'(x)p(y)$ and so there is a function $F$ such that: $$F_x=f(x)g(y),~~F_y=h(x)p(y)$$ Let's assume the $p(y)\neq0$ for a while. We have $$F(x,y)=g(y)\int f(x)dx+K(y)$$ and then $$F_y=g'(y)\int f(x)dx+K'(y)=h(x)p(y)$$ so $$h(x)=\frac{g'(y)}{p(y)}\int f(x)dx+\frac{K'(y)}{p(y)}$$ for a suitable function $K(y)$.
Almost, but not quite. Rather, under mild assumptions on your functions, you have that $$h^\prime(x) = C f(x), \quad g^\prime(y) = C p(y)$$ for some constant $C \in \mathbb{R}$, which need not be equal to $1$.
Suppose that your equation is indeed exact, so that, as you observed, $f(x)g^\prime(y) = h^\prime(x)p(y)$. Then, whenever $f(x) \neq 0$ and $p(y) \neq 0$, $$\frac{h^\prime(x)}{f(x)} = \frac{g^\prime(y)}{p(y)}.$$
Now, suppose for simplicity that all your functions are $C^1$ and that, indeed, $f(x) \neq 0$ and $p(y) \neq 0$ for all but finitely many $x$ and $y$. Then, on the complement of a finite number of points $(x,y)$, we can define $$F(x,y) := \frac{h^\prime(x)}{f(x)} = \frac{g^\prime(y)}{p(y)},$$ which therefore has $\tfrac{\partial F}{\partial x} = 0$ and $\tfrac{\partial F}{\partial y} = 0$. Thus, $F(x,y) = C$ for some constant $C$, and hence $$h^\prime(x) = C f(x), \quad g^\prime(y) = C p(y)$$ for all but finitely many $x$ and $y$; by continuity of $f$, $g^\prime$, $h$, and $p$, these equalities are therefore true for all $x$ and $y$. Note that $C$ need not be $1$, as you guessed. If you have seen any PDE, this is the same basic argument as that underpinning separation of variables.