first,
"where username =$username"
the username surely is a string, isn't it?
use quotes:
"where username='$username'"
(the same for set posts='$contents')
second,
read the mysql functions reference.
mysql_query returns a result resouce id, not the result itself. you can grasp it using maysql_fetch_array, for example.