This paper reports two alkaline-earth metal phosphonates with formulae M(4-cppH 2 ) 2 [M=Sr (1), Ba (2); 4-cppH 3 =4-carboxylphenylphosphonic acid]. Compound 1 shows a chain structure made up of edge-sharing {SrO 8 } polyhedra and {PO 3 C} tetrahedra. While in compound 2, the edge-sharing {BaO 8 } polyhedra are connected by the {PO 3 C} tetrahedra to form a two-dimensional inorganic layer. Neighboring chains in 1 or layers in 2 are cross-linked by hydrogen bond interactions between the protonated carboxylate groups, resulting in three-dimensional supramolecular structures. The magnesium alloys coated with 1 or 2 films show significantly improved anti-corrosion behaviors compared to the bare substrate.