My TV is a Sanyo HDTV, 1080p. I heard that if shoot at 720p the quality of the video is the same.
Can anyone explain if there is a difference between the two resolutions, and in which case I use one or the other?
Whoever told you that was wrong. "1080p" has 1920 horizontal pixels and 1080 vertical pixels. "720p" has 1280 horizontal pixels and 720 vertical ones. See this wikipedia page. You would want to use 1080p whenever you want the highest quality your television is capable of reproducing. The only reason you'd use 720p is if file size is a concern, or if your television doesn't really go up to 1080p.
1080p on a native 1080p TV will always be (much) higher quality than 720p on the same screen. The only thing I can think of that they might have been thinking is that 1080i on some TVs is lower than 1080p if they have a particularly bad de-interlacer (drop one of the two frames). This would result in a 540p video stream. 1080p is always higher quality than 720p as long as your TV supports 1080p natively.
If your TV only supports 720p, then 720p will be higher quality than a down-converted 1080p if 720p matches the pixel ratio of your screen. This is because whenever an image is scaled(either up or down), it doesn't match up exactly with the pixels that physically make up your screen and some amount of approximation has to be done to figure out what color should be displayed for each pixel. This results in a (slight) loss of sharpness in the image compared to a native resolution.
This is also why there is typically a (Recommended) setting in Windows on most LCD computer monitors.