Fix MySQL syntax error and table/column name mismatches