Prove that $ \int_a^x f\,dx=0$ for all $x\in [a,b]$ implies $ \int_a^b fg\,dx=0$ for any integrable $g$.
One can indeed show that $\int_a^x f(t)\,dt=0$ for all $x \in [a, b]$ implies that $\int_a^b f^2(x)\,dx = 0$ (which implies the desired conclusion, as you already noticed):
Assume on the contrary that $I = \int_a^b f^2(x)\,dx > 0$. It follows that for every sufficiently fine partition $a = x_0 < x_1 < \ldots <x_n = b$ and arbitrary “tags” $t_i \in [x_{i-1}, x_i]$ $$ \sum_{i = 1}^n f^2(t_i) (x_i - x_{i-1}) > \frac 12 I > 0 \, . $$ In particular there must be an interval $[x_{i-1}, x_i]$ such that $$ c = \inf \{ f^2(x) | x_{i-1} \le x \le x_i \} > 0 \, . $$ Then $$ \int_{x_{i-1}}^{x_i} f(t) \, dt \ge \sqrt c (x_i - x_{i-1}) > 0 $$ in contradiction to $$ \int_{x_{i-1}}^{x_i} f(t) \, dt = \int_a^{x_i} f(t)\,dt - \int_a^{x_{i-1}} f(t)\,dt = 0 \, . $$
If $g$ is integrable in the Riemannian sense, then $g$ is bounded. Say $$ m \leq g(x) \leq M $$ for all $x \in [a,b]$. Then by monotonicity of the integral we have that
$$ m \int_a^b f(x) dx \leq \int_{a}^b f(x) g(x) dx \leq M \int_{a}^{b} f(x) dx. $$
Yet $$ \int_a^b f(x) dx = 0 $$ therefore $$ 0 \leq \int_a^b f(x) g(x) dx \leq 0. $$
As was pointed out in the comment below, this works for $f \geq 0$. To fix this write observe that $$ \int_a^b f(x) dx = 0 \Rightarrow \int_a^b f^2(x) dx = 0. $$ A proof of this fact is done below. Then run the above argument with $f^2(x)$ instead of just $f$.
Let $F(x) =\int_{a} ^{x} f(t) \, dt$ so that $F(x) =0$ on whole of $[a, b] $. Next we observe that if $[c, d] $ is a sub-interval of $[a, b] $ then $f$ is continuous at some point $\xi\in[c, d] $ and thus $f(\xi) =F'(\xi) =0$ via Fundamental Theorem of Calculus.
Next let us assume that $\int_{a} ^{b} f(x) g(x)\, dx>0$ (the case of $<0$ can be handled by replacing $g$ with $-g$). Then there is sub-interval $[c, d] $ of $[a, b] $ of positive length on which $f(x) g(x) >0$. But this contradicts the fact that $f$ vanishes somewhere on this sub-interval. The contradiction proves the desired result.