Fixed sql error causeing files not to be inserted