Python and problem in updating a mysql table with simple list.

I have a list which I am using to  update  a mysql table - registrations. and a particular column 'cheapbuy' and row memberID = 3001

The list is [9, 10]  and I have verified that it is 'of type' list.

The page with the mysql update function is shown below.

The error message is also shown below

Thanks for taking a look


ERRORMESSAGE.jpgmysql registrations table

import cgi,cgitb
import mysql.connector as conn
import collections
import datetime
def htmlTop():
        <!DOCTYPE html>
        <html lang="en">
                #<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <title> My Server-side template</title>

def htmlTail():
    print(""" its done</body>

def connectDB():
    db=conn.connect(host='localhost' ,user='root' ,passwd='844cheminduplan' ,db='office')
    cursor = db.cursor()
    return db, cursor 

def Updatecheapbuy(db,cursor):
    cursor.execute ("""
       UPDATE registrations
       SET  cheapbuy = {0}
       WHERE memberID={1}
    """.format(cheapbuylist, memberID))

#main program
if __name__== "__main__":
        memberID = 1003
        mydict = ({9: 3, 10: 3, 11: 1, 12: 1})
        cheapbuylist = []
        for key, value in mydict.items():
            if value == 3:
                print(key, "this is key")
        print(cheapbuylist, "this is cheapbuylist", type(cheapbuylist), memberID, "This is memberID")




Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Walter RitzelSenior Software EngineerCommented:
James, can you print the statement before execute and put the result here? I believe your problem is that your command is expecting a string, but you are delivering the value without quotes

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jameskaneAuthor Commented:
Hi Walter, sorry, but I'm not sure what you mean 'statement before execute'  ?
jameskaneAuthor Commented:
OK, that's fixed - needed the string change plus Json.


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.