Remember, mysql_error() will always be your friend.
This SQL segment doesn't make sense:
order by rand()
rand() is a function. It returns a random number. Order of operations dictate that it figures out the number first and then does the order by. So what you are really saying:
order by [field named: random number selected by rand()]
But I bet your fields are not numeric. Order by can only sort by field names.
order by [existing field name] <-- will work