The problem is that you need to pick the closest intersection point to the camera: for a sphere, there are usually two. If your camera only stays outside or inside, you can always use the same formula, otherwise you need to calculate both and compare them.
Copying k codes is pretty dumb though: the equation for a sphere around the origin is: x^2 + y^2 + z^2 = radius^2
If you've read my little raytracing intro, this should be enough to get you started and derive the k formula yourself.
