Python Forum

Full Version: MYSQL Update Query format
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am having trouble getting a database UPDATE query to run using variables. I get an error message of "1054 (42S22): Unknown column 'channel_bandwidth' in 'field list'". Update code is

cursor.execute("UPDATE tower_aps SET channel_bandwidth = '%s', \
        color_code = '%s', tx_freq = '%s', cust_count = '%s' \
        WHERE name = '%s'"% (chan,color,freq,sms,ap_name) )
Everything I am reading says it's a quoting problem but I have tried many different variations.

thx

simdo01
Quote:
WHERE name = '%s'"% (

Don't use string formatting at all (the %). Let the database engine handle quoting/escaping for you. Try this:
query = '''
UPDATE tower_aps SET channel_bandwidth = '%s',
    color_code = '%s', tx_freq = '%s', cust_count = '%s'
WHERE name = '%s'
'''

cursor.execute(query, (chan, color, freq, sms, ap_name))