fix sql syntax and array problem