I have no idea what I do wrong... this is my code:
SELECT * FROM messages WHERE userId = \"6\" OR toUserId = \"6\" OR toAll = \"1\" AND id <> \"4\" ORDER
You need to use parenthesis to indicate operator precedence:
WHERE ( userId = "6" OR toUserId = "6" OR toAll = "1" ) AND id <> "4"