From the error, it sort of looks like maybe the variable $user_id has no value. In any case, I would recommend you use the following pattern for submitting queries, so that if there is an error you can see the query exactly as it was submitted to MySQL:
$query = "SELECT COUNT(*) FROM ratings WHERE user_id = $user_id AND product_id = $id";
$result = mysql_query($query) or die("Query failed ($query): " . mysql_error());