I read from a textbook that
The essential point to understand about a line integral is that there is one independent variable, because we are required to remain on a curve.
How does remaining on a curve result in only one independent variable for the line integral, for both 2D and 3D cases?
Any curve can be parametrized by a function $f(t)$, where $t \in [0,1]$ typically.
$f(0)$ represents the beginning, or start of your curve, and $f(1)$ the end. If your curve is in multiple dimensions, you can parametrize it such that each of the functions depends on only the variable $t$:
$$x(t) = \quad ...$$ $$y(t) = \quad ...$$ $$z(t) = \quad ...$$
You can thus project your curve in $n$-dimensional space onto each dimension, $x, y, z$, etc... and then define a function that will parameterize that dimension. This system of equations only depends on a single parameter, $t$, which dictates which $x, y,$ and $z$ coordinates must be taken in order to "stay on the curve".