I'm reviewing the book "Conquering the Physics GRE" for my upcoming Physics GRE. I came across this problem which I'm having trouble with understanding. In particular, I understand the solution that the author provides but I don't understand what is wrong with my approach.
Q. The Electric field inside a sphere of radius $R$ is given by $E = E_0 z^2 \hat{\textbf{z}}$. What is the total charge of the sphere?
The authors approach involving taking the divergence of the electric field to get the charge density and then integrating the density over the volume of the sphere to get charged enclosed, which in their case turns out to be $0$.
But we can also just use a concentric sphere of radius $r$ ($0 < r \le R$) as a Gaussian surface and just use the integral form of Maxwell's equation to calculate the charge enclosed.
$$ \oint \limits_{S} \vec{E} \cdot d\vec{S} = \frac{Q_{enc}}{\epsilon_0} .$$
Since the area vector points in the radial direction, if we assume it makes an angle $\theta$ with the Electric Field vector, and given $z = r cos(\theta)$, we have
$$ Q_{enc} = \epsilon_0 \int \limits_{0}^{\pi} \int \limits_{0}^{2\pi} E_0 r^2 cos^2(\theta) r^2 sin(\theta) d\theta d\phi,$$
$$ Q_{enc} = \frac{4 \pi \epsilon_0 E_0}{3} r^4 . $$
If we want the charge enclosed by the sphere, we just set $r = R$, so we get
$$ Q = \frac{4 \pi \epsilon_0 E_0}{3} R^4 .$$
which isn't zero.
I'm having trouble figuring out where I'm going wrong. Any suggestions appreciated.