Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MYSQL Update Query format
#1
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
Reply
#2
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))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysql and mysql.connector error lostintime 2 668 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,000 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python ilknurg 3 5,597 Jan-18-2022, 06:25 PM
Last Post: ilknurg
  How do you format Update statement with multiple conditions hammer 4 2,095 Dec-16-2021, 10:49 PM
Last Post: hammer
  Problem Using SQL Placeholder In MySQL Query AdeS 11 6,095 Jul-31-2021, 12:19 AM
Last Post: Pedroski55
Question Python + Google Sheet | Best way to update specific cells in a single Update()? Vokofe 1 2,676 Dec-16-2020, 05:26 AM
Last Post: Vokofe
  Format SQL Query Output phillyfa 2 4,047 Apr-22-2020, 07:45 AM
Last Post: buran
  Python mysql query help please tduckman 4 4,310 Mar-13-2020, 03:42 PM
Last Post: Marbelous
  Looking for an up to date example to query mysql UtiliseIT 5 3,580 Feb-19-2019, 05:35 AM
Last Post: UtiliseIT

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020