Accounting for sql errors

changed a confusing variable name