This paper deals with two subjects and their interaction. The first is the problem of spanning spaces of modular forms by theta series. The second is the commutative algebraic properties of Hecke modules arising in the arithmetic theory of modular forms.Let p be a prime, and let B denote the quaternion algebra over Q that is ramified at p and ∞ and at no other places. If L is a left ideal in a maximal order of B, then L is a rank four Z-module equipped in a natural way with a positive definite quadratic form [6, §1]. (We shall say that L is a rank four quadratic space, and remark that the isomorphism class of L as a quadratic space depends only on the left ideal class of L in its maximal order.) Eichler [5] proved that the theta series of L is a weight two modular form on Γ 0 (p), and that as L ranges over a collection of left ideal class representatives of all left ideals in all maximal orders of B these theta series span the vector space of weight two modular forms on Γ 0 (p) over Q.In this paper we strengthen this result as follows: if L is as above, then the q-expansion of its theta series Θ(L) has constant term equal to one and all other coefficients equal to even integers. Suppose that f is a modular form whose qexpansion coefficients are even integers, except perhaps for its constant term, which we require merely to be an integer. It follows from Eichler's theorem that f may be written as a linear combination of Θ(L) (with L ranging over a collection of left ideals of maximal orders of B) with rational coefficients. We show that in fact these coefficients can be taken to be integers.Let T denote the Z-algebra of Hecke operators acting on the space of weight two modular forms on Γ 0 (p). The proof that we give of our result hinges on analyzing the structure of a certain T-module X . We can say what X is: it is the free Zmodule of divisors supported on the set of singular points of the (reducible, nodal) curve X 0 (p) in characteristic p. The key properties of X , which imply the above result on theta series, are that the natural map T −→ End T (X ) is an isomorphism, and that furthermore X is locally free of rank one in a Zariski neighbourhood of the Eisenstein ideal of T. We remark that it is comparatively easy to prove the analogous statements after tensoring with Q, for they then follow from the fact that X is a faithful T-module. Indeed, combining this with the semi-simplicity of the Q-algebra T⊗ Z Q, one deduces that X ⊗ Z Q is a free T⊗ Z Q-module of rank one, and in particular that the map T ⊗ Z Q −→ End T⊗ Z Q (X ⊗ Z Q) is an isomorphism.