Security - spammers

Hi there,
I found out this morning that my site got hacked by i assume a spammer who added a line onto my index page and dump files and folders.

I do keep in mind security in terms of username and password and i still dont understand how come he was able to add a line onto the index.php.

Can somebody help me understand what could have happened and what can i do to keep thoses useless people away from my site.

Thanks again for any help,

Regards

Jerome