Query works in mysql shell, fails in php

The following query works in mysql shell but gives me a "fatal error, Unknown column ‘t2.country’ in ‘field list’ " in php.

Update  download t2, ip_lookup t1
set     t2.country = t1.country,
        t2.area = t1.area,
        t2.city = t1.city
where   ((t2.IP_ADDRESS) BETWEEN (t1.start_ip) AND (t1.end_ip)) AND       
        t2.FILENAME is not null and t2.country is null;

Does anyone have a suggestion on the best way to fix this? Could this be set up as a trigger on row insert in the download table so it doesn’t have to be updated later?