I want to prove that if $p$ is a prime, then we have $$\begin{align*} x^{p-1}-1 \equiv (x-1)\cdots (x-(p-1)) \pmod{p} \end{align*}$$ for all $x$
My attempt: $$\begin{align*}
f(x)&= a_nx^n+\cdots +a_0 \\ &&(1) \\ f(x) & \equiv 0 \pmod{p}
\end{align*}$$
I use a lemma that if $p$ is a prime and $p \nmid a_n$ , and suppose $x \equiv \alpha_i \pmod{p}, \ i=1,\cdots ,k\le n$ are different solutions to $(1)$
Then we have $$\begin{align*}
f(x) \equiv (x-\alpha_1)\cdots (x-\alpha_k) f_k(x) \pmod{p}
\end{align*}$$ where $f_k(s)$ is a polynomial with $\deg f_k=n-k$ and $a_n$ is the coefficient of first term in $f_k(x)$ .
Then consider the polynomial $f(x)=x^{p-1}-1$ . By Fermat's little theorem, if $(x,p)=1$ , then we have $f(x) \equiv 0 \pmod{p}$ . Thus, under modulo $p$ , solutions are $x\equiv 1,2,\cdots ,p-1 \pmod{p}$ , and hence by lemma :$$\begin{align*} f(x) \equiv (x-1)\cdots (x-(p-1)) \cdot1 \pmod{p} \end{align*}$$ Now my $x$ doesn't have any restriction. I just change the "form" of $x^{p-1}-1$ under modulo $p$ , since all I did was to find the solutions to $$\begin{align*} f(x) \equiv 0 \pmod{p} \end{align*}$$ . They are $1,2,\ldots ,p-1$ and use the lemma to write my $f(x)$ into another form under modulo $p$
On the other hand, I found that I can also consider the polynomial $f(x)=x^p-x$. By Fermat's little theorem, now all integers are solutions to $f(x) \equiv 0 \pmod{p}$, so under modulo, $p$, $x \equiv 0,1,\ldots,p-1$ are different solutions to it. By lemma, I have $$\begin{align*} x^p-x \equiv x(x-1)\cdots (x-(p-1)) \pmod{p} \end{align*}$$ Then, if $(x,p)=1$ , I can further get $$\begin{align*} x^{p-1}-1 \equiv (x-1)\cdots (x-(p-1)) \pmod{p} \end{align*}$$ But now, in the equation above, I assume that $x$ can only by coprime to $p$, not like the first trial in that I proved that the equation $x^{p-1}-1 \equiv (x-1)\cdots (x-(p-1)) \pmod{p}$ is right for all $x$.
I'm confused here. What's going wrong? Thank you very much!
(By the way: I'sorry that I don't know anything about the group, ring, field theory, abstract algebra, and things like these)