Generally I have found that the stuff right before the printed error is USUALLY the real cause, so I look at this:

WHERE language_id = $this_language_id

and I see that if $this_language_id is null, which I bet it is, it will throw an error.
Always a good idea to do this:
language_id = '$this_language_id'
... for one thing, many a hack was done with a quoteless ID. Look up SQL-injection for the gory details.

Anyway, may I suggest putting this in your toolbox:


$sql="some query";
$db=mysql_query($sql);
$ref = mysql_fetch_row($db);
if (mysql_error()){
print mysql_error()."<br>$sql<br>";
exit();
}

Seeing the Actual SQL after an error can usually speed up debugging by thousands!