I just tried to jump start a friend's car. When I connected the jumper cables, there were a lot of sparks. They were connected for nearly 30 seconds and I noticed a lot of heat and smoke coming from both batteries. I immediately disconnected and didn't try again. I didn't even start the car with the good battery. Why was this, and what can I do to avoid it?
With the description you give, I'd say you connected them backwards with about a 99%+ assurance. Large amounts of sparks followed by heat are both VERY BAD SIGNS (as you soon figured out) and almost always mean you have the jumpers on backwards. Never trust what the covers on the battery says. Check what the battery says to be sure. If there is no way to see what is on the battery (the terminals cover them), follow the cables back to their source. The negative will go to a ground and the positive will go to the starter and to the alternator. If those are correct, ensure that the jumper cables are correctly aligned. Some sets I've seen will have black shielding on both with a thin yellow (or some other color) stripe up them. It would be very easy to mix these up. If you still think it was right, you could ultimately check each side of the jumper cables for continuity to ensure you are matching them up.
It is probably a short on your positive battery terminal causing it to ground out, which virtually gives you two negatives. I would recommend pulling off your positive cable all the way from the starter and the fuse box and inspect it to make sure there are no cracks, splits or melted/bare spots. Replace if needed and hopefully there is not too much damage from the short.