python/mysql UPDATE syntax problem

I have a CGI action page being fed from a form.   I have attached the code for this page.  Originally it was used to INSERT a new record and this works (see lines 66/70 of code for related  function. I am changing the page to provide UPDATE functionality only (lines 74 / 81 of code- but this is not functioning properly. I get the following error :

ERROR MESSAGE
I'm missing some subtle syntax point or some basic concept. Thanks for any pointer to a fix.

James

#!C:\Python34\python.exe
import cgi
import cgitb
import mysql.connector as conn
def htmlTop():
    print("""Content-type:text/html\n\n
        <!DOCTYPE html>
        <html lang="en">
            <head>
                #<meta charset="utf-8"/>
                <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
                <title> My Server-side template</title>
        </head>
        <body>""")

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

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

def getData():
    formData = cgi.FieldStorage()
    #selection = formData.getlist('selection')
    selection = formData.getlist('selection')
    selectionTWO = formData.getlist('selectionTWO')
    selectionTHREE = formData.getlist('selectionTHREE')
    memberID = formData.getlist('memberID')
    return selection,selectionTWO,selectionTHREE,memberID


def killcommasselection(selection):
    newlist =[]
    for m in selection:
        MC= int(m[:])
        newlist.append(MC)
        selection = newlist
    return selection



def killcommasselectionTHREE(selectionTHREE):
    newlist =[]
    for m in selectionTHREE:
        MC= int(m[:])
        newlist.append(MC)
        selectionTHREE = newlist
    return selectionTHREE



def killcommasselectionTWO(selectionTWO):
    newlist =[]
    for m in selectionTWO:
        MC= int(m[:])
        newlist.append(MC)
        selectionTWO = newlist
    return selectionTWO


    
#def insertinfo2(db,cursor):
    #strSQL = "insert into registrations(memberID, T1ytdlatest, T2ytdlatest, T3ytdlatest, T1ytd, T2ytd, T3ytd) values ({0}, '{1}', '{2}', '{3}', '{1}', '{2}', '{3}')".format(mylist[0], mylist[1], mylist[2], mylist[3])
    #cursor.execute(strSQL)
    #db.commit()     
    #db.close() 
    

    
def UpdateInfo2(db,cursor):
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytdlatest=%s, T2ytdlatest=%s, T3ytdlatest=%s
       WHERE memberID=%s
    """ ('{1}', '{2}', '{3}','{0}').format(mylist[1], mylist[2], mylist[3],mylist[0] ))
    db.commit()
    db.close
     
    
#main program
if __name__== "__main__":
    try:
        htmlTop()
        db,cursor=connectDB()
        selection,selectionTWO,selectionTHREE,memberID = getData()
        print(selection)
        print(selectionTWO)
        print(selectionTHREE)
        print(memberID)
        killcommasselection(selection)
        selection = killcommasselection(selection)
        killcommasselectionTWO(selectionTWO)
        selectionTWO = killcommasselectionTWO(selectionTWO)
        killcommasselectionTHREE(selectionTHREE)
        selectionTHREE = killcommasselectionTHREE(selectionTHREE)
        memberID = ''.join(memberID)
        mylist =[memberID, selection, selectionTWO, selectionTHREE]
        print (mylist, "this is mylist,")
        print(memberID, "this is memberID")
        #insertinfo2(db,cursor)
        UpdateInfo2(db,cursor)
        print("Update SUCCESSFULL")
        htmlTail()
    except:
        cgi.print_exception()

Open in new window


Table being updated - [] 's are replaced by lists - like in other rows
jameskaneAsked:
Who is Participating?

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

x
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.

Steve BinkCommented:
I believe you want a '%' between your query  and the replacement tokens on line 79:
def UpdateInfo2(db,cursor):
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytdlatest=%s, T2ytdlatest=%s, T3ytdlatest=%s
       WHERE memberID=%s
    """ % ('{1}', '{2}', '{3}','{0}').format(mylist[1], mylist[2], mylist[3],mylist[0] ))
    db.commit()
    db.close

Open in new window


The error is happening because you are defining a string (the query).  The parenthesis directly after it turn it into a function call.  The result of that supposed function call would be fed to cursor.execute() as the first parameter.  Putting the '%' symbol there tells Python to format the previous string with the tokens found in the following list.
jameskaneAuthor Commented:
Many thanks for reply. I have made the change, but now bumped into another error - see error message  below
and the revised page code with the change you recommended. As you probably realized, I'm a bit of an novice at this !!

New Error Message
#!C:\Python34\python.exe
import cgi
import cgitb
import mysql.connector as conn
def htmlTop():
    print("""Content-type:text/html\n\n
        <!DOCTYPE html>
        <html lang="en">
            <head>
                #<meta charset="utf-8"/>
                <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
                <title> My Server-side template</title>
        </head>
        <body>""")

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

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

def getData():
    formData = cgi.FieldStorage()
    #selection = formData.getlist('selection')
    selection = formData.getlist('selection')
    selectionTWO = formData.getlist('selectionTWO')
    selectionTHREE = formData.getlist('selectionTHREE')
    memberID = formData.getlist('memberID')
    return selection,selectionTWO,selectionTHREE,memberID


def killcommasselection(selection):
    newlist =[]
    for m in selection:
        MC= int(m[:])
        newlist.append(MC)
        selection = newlist
    return selection



def killcommasselectionTHREE(selectionTHREE):
    newlist =[]
    for m in selectionTHREE:
        MC= int(m[:])
        newlist.append(MC)
        selectionTHREE = newlist
    return selectionTHREE



def killcommasselectionTWO(selectionTWO):
    newlist =[]
    for m in selectionTWO:
        MC= int(m[:])
        newlist.append(MC)
        selectionTWO = newlist
    return selectionTWO


    
#def insertinfo2(db,cursor):
    #strSQL = "insert into registrations(memberID, T1ytdlatest, T2ytdlatest, T3ytdlatest, T1ytd, T2ytd, T3ytd) values ({0}, '{1}', '{2}', '{3}', '{1}', '{2}', '{3}')".format(mylist[0], mylist[1], mylist[2], mylist[3])
    #cursor.execute(strSQL)
    #db.commit()     
    #db.close() 
    

    
def UpdateInfo2(db,cursor):
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytdlatest=%s, T2ytdlatest=%s, T3ytdlatest=%s
       WHERE memberID=%s
    """ % ('{1}', '{2}', '{3}','{0}').format(mylist[1], mylist[2], mylist[3],mylist[0] ))
    db.commit()
    db.close
     
    
#main program
if __name__== "__main__":
    try:
        htmlTop()
        db,cursor=connectDB()
        selection,selectionTWO,selectionTHREE,memberID = getData()
        print(selection)
        print(selectionTWO)
        print(selectionTHREE)
        print(memberID)
        killcommasselection(selection)
        selection = killcommasselection(selection)
        killcommasselectionTWO(selectionTWO)
        selectionTWO = killcommasselectionTWO(selectionTWO)
        killcommasselectionTHREE(selectionTHREE)
        selectionTHREE = killcommasselectionTHREE(selectionTHREE)
        memberID = ''.join(memberID)
        mylist =[memberID, selection, selectionTWO, selectionTHREE]
        print (mylist, "this is mylist,")
        print(memberID, "this is memberID")
        #insertinfo2(db,cursor)
        UpdateInfo2(db,cursor)
        print("Update SUCCESSFULL")
        htmlTail()
    except:
        cgi.print_exception()

Open in new window

Steve BinkCommented:
Well, it was late when I responded.  :)

For the token replacement, you can use either '%' or .format(), but you have both.  Examples below:
>>> print "This is %s %d of string formatting" % ('example',1)
This is example 1 of string formatting
>>> print "This is %(t)s %(n)d of string formatting" % {'t':'example', 'n':2}
This is example 2 of string formatting
>>> print "This is {0} {1} of string formatting".format('example',3)
This is example 3 of string formatting
>>> print "This is {type} {num} of string formatting".format(type='example', num=4)
This is example 4 of string formatting

Open in new window


Be mindful of the syntax difference between the two approaches.  See the docs for a more in-depth explanation.
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Walter RitzelSenior Software EngineerCommented:
Hi James, I got later to your question, but here is how you should write this down, according to the code that you have already written in the past:
def UpdateInfo2(db,cursor):
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytdlatest={1}, T2ytdlatest={2}, T3ytdlatest={3}
       WHERE memberID={4}
    """.format(mylist[1], mylist[2], mylist[3],mylist[0] ))
    db.commit()
    db.close

Open in new window

Steve BinkCommented:
Some minor adjustments to Walter's solution:
def UpdateInfo2(db,cursor):
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytdlatest={1}, T2ytdlatest={2}, T3ytdlatest={3}
       WHERE memberID={0}
    """.format(*mylist)
    db.commit()
    db.close

Open in new window


The string formatting placeholders begin at 0, not 1.  I also rearranged the numbers to facilitate using the list's ability to parameterize itself,
jameskaneAuthor Commented:
Million thanks Steve and  Walter.  I am learning so much from this !

Unfortunately I am seeing the same error message on both approaches


Steve, this is what I get with your function
This is the page code as it now   stands

#!C:\Python34\python.exe
import cgi
import cgitb
import mysql.connector as conn
def htmlTop():
    print("""Content-type:text/html\n\n
        <!DOCTYPE html>
        <html lang="en">
            <head>
                #<meta charset="utf-8"/>
                <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
                <title> My Server-side template</title>
        </head>
        <body>""")

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

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

def getData():
    formData = cgi.FieldStorage()
    #selection = formData.getlist('selection')
    selection = formData.getlist('selection')
    selectionTWO = formData.getlist('selectionTWO')
    selectionTHREE = formData.getlist('selectionTHREE')
    memberID = formData.getlist('memberID')
    return selection,selectionTWO,selectionTHREE,memberID


def killcommasselection(selection):
    newlist =[]
    for m in selection:
        MC= int(m[:])
        newlist.append(MC)
        selection = newlist
    return selection



def killcommasselectionTHREE(selectionTHREE):
    newlist =[]
    for m in selectionTHREE:
        MC= int(m[:])
        newlist.append(MC)
        selectionTHREE = newlist
    return selectionTHREE



def killcommasselectionTWO(selectionTWO):
    newlist =[]
    for m in selectionTWO:
        MC= int(m[:])
        newlist.append(MC)
        selectionTWO = newlist
    return selectionTWO


    
#def insertinfo2(db,cursor):
    #strSQL = "insert into registrations(memberID, T1ytdlatest, T2ytdlatest, T3ytdlatest, T1ytd, T2ytd, T3ytd) values ({0}, '{1}', '{2}', '{3}', '{1}', '{2}', '{3}')".format(mylist[0], mylist[1], mylist[2], mylist[3])
    #cursor.execute(strSQL)
    #db.commit()     
    #db.close() 
    

    
#def UpdateInfo2(db,cursor):
    #cursor.execute ("""
       #UPDATE registrations
       #SET  T1ytdlatest=%s, T2ytdlatest=%s, T3ytdlatest=%s
       #WHERE memberID=%s
    #""" % ('{1}', '{2}', '{3}',{0}).format(eval(mylist[1], mylist[2], mylist[3], mylist[0]) ))
    #db.commit()
    #db.close
    
#def UpdateInfo2(db,cursor):
    #cursor.execute ("""
       #UPDATE registrations
       #SET  T1ytdlatest={1}, T2ytdlatest={2}, T3ytdlatest={3}
       #WHERE memberID={4}
    #""".format(mylist[1], mylist[2], mylist[3],mylist[0] ))
    #db.commit()
    #db.close
    
def UpdateInfo2(db,cursor):
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytdlatest={1}, T2ytdlatest={2}, T3ytdlatest={3}
       WHERE memberID={0}
    """ .format(*mylist)
    db.commit()
    db.close
     
    
#main program
if __name__== "__main__":
    try:
        htmlTop()
        db,cursor=connectDB()
        selection,selectionTWO,selectionTHREE,memberID = getData()
        print(selection)
        print(selectionTWO)
        print(selectionTHREE)
        print(memberID)
        killcommasselection(selection)
        selection = killcommasselection(selection)
        killcommasselectionTWO(selectionTWO)
        selectionTWO = killcommasselectionTWO(selectionTWO)
        killcommasselectionTHREE(selectionTHREE)
        selectionTHREE = killcommasselectionTHREE(selectionTHREE)
        memberID = ''.join(memberID)
        mylist =[memberID, selection, selectionTWO, selectionTHREE]
        print (mylist, "this is mylist,")
        print(memberID, "this is memberID")
        #insertinfo2(db,cursor)
        UpdateInfo2(db,cursor)
        print("Update SUCCESSFULL")
        htmlTail()
    except:
        cgi.print_exception()

Open in new window


James
error-message5.jpg
Steve BinkCommented:
The error message you posted is referencing a piece of commented code.  Try running it again, making sure that UpdateInfo2() found at lines 92-99 is running.
Walter RitzelSenior Software EngineerCommented:
in fact, the last code has one minor mistake: the parenthesis for execute function was not closed.
jameskaneAuthor Commented:
Hi Walter, Steve.  I  have run the  corrected function as below - but there is still a problem. Looks very close though. Thanks for your patience !

Error Message

error messagee
def UpdateInfo2(db,cursor):
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytdlatest={1}, T2ytdlatest={2}, T3ytdlatest={3}
       WHERE memberID={0}
    """ .format(*mylist))
    db.commit()
    db.close

Open in new window

jameskaneAuthor Commented:
Further to response above...

When I run

def UpdateInfo2(db,cursor):
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytdlatest={1}, T2ytdlatest={2}, T3ytdlatest={3}
       WHERE memberID={4}
    """.format(mylist[1], mylist[2], mylist[3],mylist[0] ))
    db.commit()
    db.close

I get the error message

error message
Walter RitzelSenior Software EngineerCommented:
start the {} with zero instead of one.
jameskaneAuthor Commented:
Hi Walter,

have tired the function below as you suggested. Error message and complete code page below. Seems to me that {0} is correct for memberID ??

def UpdateInfo2(db,cursor):
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytdlatest={0}, T2ytdlatest={1}, T3ytdlatest={2}
       WHERE memberID={3}
    """.format(*mylist))
    db.commit()
    db.close

Open in new window


error message  

#!C:\Python34\python.exe
import cgi
import cgitb
import mysql.connector as conn
def htmlTop():
    print("""Content-type:text/html\n\n
        <!DOCTYPE html>
        <html lang="en">
            <head>
                #<meta charset="utf-8"/>
                <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
                <title> My Server-side template</title>
        </head>
        <body>""")

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

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

def getData():
    formData = cgi.FieldStorage()
    #selection = formData.getlist('selection')
    selection = formData.getlist('selection')
    selectionTWO = formData.getlist('selectionTWO')
    selectionTHREE = formData.getlist('selectionTHREE')
    memberID = formData.getlist('memberID')
    return selection,selectionTWO,selectionTHREE,memberID


def killcommasselection(selection):
    newlist =[]
    for m in selection:
        MC= int(m[:])
        newlist.append(MC)
        selection = newlist
    return selection



def killcommasselectionTHREE(selectionTHREE):
    newlist =[]
    for m in selectionTHREE:
        MC= int(m[:])
        newlist.append(MC)
        selectionTHREE = newlist
    return selectionTHREE



def killcommasselectionTWO(selectionTWO):
    newlist =[]
    for m in selectionTWO:
        MC= int(m[:])
        newlist.append(MC)
        selectionTWO = newlist
    return selectionTWO


    
#def insertinfo2(db,cursor):
    #strSQL = "insert into registrations(memberID, T1ytdlatest, T2ytdlatest, T3ytdlatest, T1ytd, T2ytd, T3ytd) values ({0}, '{1}', '{2}', '{3}', '{1}', '{2}', '{3}')".format(mylist[0], mylist[1], mylist[2], mylist[3])
    #cursor.execute(strSQL)
    #db.commit()     
    #db.close() 
    

    
#def UpdateInfo2(db,cursor):
    #cursor.execute ("""
       #UPDATE registrations
       #SET  T1ytdlatest=%s, T2ytdlatest=%s, T3ytdlatest=%s
       #WHERE memberID=%s
    #""" % ('{1}', '{2}', '{3}',{0}).format(eval(mylist[1], mylist[2], mylist[3], mylist[0]) ))
    #db.commit()
    #db.close
    
#def UpdateInfo2(db,cursor):
    #cursor.execute ("""
       #UPDATE registrations
       #SET  T1ytdlatest={1}, T2ytdlatest={2}, T3ytdlatest={3}
       #WHERE memberID={4}
    #""".format(mylist[1], mylist[2], mylist[3],mylist[0] ))
    #db.commit()
    #db.close
    
    
    
#def UpdateInfo2(db,cursor): 
    #cursor.execute ("""
       #UPDATE registrations
       #SET  T1ytdlatest={1}, T2ytdlatest={2}, T3ytdlatest={3}
       #WHERE memberID={0}
    #""".format(*mylist))
    #db.commit()
    #db.close
    
def UpdateInfo2(db,cursor):
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytdlatest={0}, T2ytdlatest={1}, T3ytdlatest={2}
       WHERE memberID={3}
    """.format(*mylist))
    db.commit()
    db.close
     
    
#main program
if __name__== "__main__":
    try:
        htmlTop()
        db,cursor=connectDB()
        selection,selectionTWO,selectionTHREE,memberID = getData()
        print(selection)
        print(selectionTWO)
        print(selectionTHREE)
        print(memberID)
        killcommasselection(selection)
        selection = killcommasselection(selection)
        killcommasselectionTWO(selectionTWO)
        selectionTWO = killcommasselectionTWO(selectionTWO)
        killcommasselectionTHREE(selectionTHREE)
        selectionTHREE = killcommasselectionTHREE(selectionTHREE)
        memberID = ''.join(memberID)
        mylist =[memberID, selection, selectionTWO, selectionTHREE]
        #mylist =[selection, selectionTWO, selectionTHREE,memberID]
        print (mylist, "this is mylist,")
        print(memberID, "this is memberID")
        #insertinfo2(db,cursor)
        UpdateInfo2(db,cursor)
        print("Update SUCCESSFULL")
        htmlTail()
    except:
        cgi.print_exception()

Open in new window

Walter RitzelSenior Software EngineerCommented:
The problem is with the suggestion given by Steven, because your fields on the mylist are not in the expected order. Try this:
def UpdateInfo2(db,cursor):
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytdlatest={0}, T2ytdlatest={1}, T3ytdlatest={2}
       WHERE memberID={3}
    """.format(mylist[1], mylist[2], mylist[3],mylist[0]))
    db.commit()
    db.close

Open in new window

jameskaneAuthor Commented:
Ah, not good I'm afraid. Error message attached and code listing for this run.
error message
#!C:\Python34\python.exe
import cgi
import cgitb
import mysql.connector as conn
def htmlTop():
    print("""Content-type:text/html\n\n
        <!DOCTYPE html>
        <html lang="en">
            <head>
                #<meta charset="utf-8"/>
                <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
                <title> My Server-side template</title>
        </head>
        <body>""")

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

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

def getData():
    formData = cgi.FieldStorage()
    #selection = formData.getlist('selection')
    selection = formData.getlist('selection')
    selectionTWO = formData.getlist('selectionTWO')
    selectionTHREE = formData.getlist('selectionTHREE')
    memberID = formData.getlist('memberID')
    return selection,selectionTWO,selectionTHREE,memberID


def killcommasselection(selection):
    newlist =[]
    for m in selection:
        MC= int(m[:])
        newlist.append(MC)
        selection = newlist
    return selection



def killcommasselectionTHREE(selectionTHREE):
    newlist =[]
    for m in selectionTHREE:
        MC= int(m[:])
        newlist.append(MC)
        selectionTHREE = newlist
    return selectionTHREE



def killcommasselectionTWO(selectionTWO):
    newlist =[]
    for m in selectionTWO:
        MC= int(m[:])
        newlist.append(MC)
        selectionTWO = newlist
    return selectionTWO


    
#def insertinfo2(db,cursor):
    #strSQL = "insert into registrations(memberID, T1ytdlatest, T2ytdlatest, T3ytdlatest, T1ytd, T2ytd, T3ytd) values ({0}, '{1}', '{2}', '{3}', '{1}', '{2}', '{3}')".format(mylist[0], mylist[1], mylist[2], mylist[3])
    #cursor.execute(strSQL)
    #db.commit()     
    #db.close() 
    

    
#def UpdateInfo2(db,cursor):
    #cursor.execute ("""
       #UPDATE registrations
       #SET  T1ytdlatest=%s, T2ytdlatest=%s, T3ytdlatest=%s
       #WHERE memberID=%s
    #""" % ('{1}', '{2}', '{3}',{0}).format(eval(mylist[1], mylist[2], mylist[3], mylist[0]) ))
    #db.commit()
    #db.close
    
#def UpdateInfo2(db,cursor):
    #cursor.execute ("""
       #UPDATE registrations
       #SET  T1ytdlatest={1}, T2ytdlatest={2}, T3ytdlatest={3}
       #WHERE memberID={4}
    #""".format(mylist[1], mylist[2], mylist[3],mylist[0] ))
    #db.commit()
    #db.close
    
def UpdateInfo2(db,cursor):
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytdlatest={0}, T2ytdlatest={1}, T3ytdlatest={2}
       WHERE memberID={3}
    """.format(mylist[1], mylist[2], mylist[3],mylist[0]))
    db.commit()
    db.close 
    
    
#def UpdateInfo2(db,cursor): 
    #cursor.execute ("""
       #UPDATE registrations
       #SET  T1ytdlatest={1}, T2ytdlatest={2}, T3ytdlatest={3}
       #WHERE memberID={0}
    #""".format(*mylist))
    #db.commit()
    #db.close
    
#def UpdateInfo2(db,cursor):
    #cursor.execute ("""
       #UPDATE registrations
       #SET  T1ytdlatest={0}, T2ytdlatest={1}, T3ytdlatest={2}
       #WHERE memberID={3}
    #""".format(*mylist))
    #db.commit()
    #db.close
     
    
#main program
if __name__== "__main__":
    try:
        htmlTop()
        db,cursor=connectDB()
        selection,selectionTWO,selectionTHREE,memberID = getData()
        print(selection)
        print(selectionTWO)
        print(selectionTHREE)
        print(memberID)
        killcommasselection(selection)
        selection = killcommasselection(selection)
        killcommasselectionTWO(selectionTWO)
        selectionTWO = killcommasselectionTWO(selectionTWO)
        killcommasselectionTHREE(selectionTHREE)
        selectionTHREE = killcommasselectionTHREE(selectionTHREE)
        memberID = ''.join(memberID)
        mylist =[memberID, selection, selectionTWO, selectionTHREE]
        #mylist =[selection, selectionTWO, selectionTHREE,memberID]
        print (mylist, "this is mylist,")
        print(memberID, "this is memberID")
        #insertinfo2(db,cursor)
        UpdateInfo2(db,cursor)
        print("Update SUCCESSFULL")
        htmlTail()
    except:
        cgi.print_exception()

Open in new window

Walter RitzelSenior Software EngineerCommented:
try this:
def UpdateInfo2(db,cursor):
    cursor.execute ("""
       UPDATE registrations
       SET  T1ytdlatest='{0}', T2ytdlatest='{1}', T3ytdlatest='{2}'
       WHERE memberID={3}
    """.format(mylist[1], mylist[2], mylist[3],mylist[0]))
    db.commit()
    db.close 

Open in new window

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:
DONE !!!  Works perfectly.

Many thanks  for your patience !
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
Python

From novice to tech pro — start learning today.