Avatar of jameskane
jameskane
 asked on

Python mysql Insert data error

I have a form and supporting action page. Variables are passed successfully to the action page, but I have  an error from the action page on trying to Insert the data into the mysql table.
(error is mysql.connector.errors.DataError: 1136 (21S01): Column count doesn't match value count at row 1)

I have triple checked that the Insert Function and the mysql columns match. So I'm a bit lost as to what the problem might be.

Below please find the
- The insert function
- Section of the action page which deploys the function
- Corresponding mysql table structure
- Error Message - note that line 81 referred to in message is the .format line of the insert function.

Many thanks for your help

james



def Insertmembers2(db,cursor):
    cursor.execute("""
    INSERT into members2 (memberID, civilities, Nom, Prenom, Adresse, ZIP, Ville, tel, mobile, email, nomresponsible, prenomresponsible, Naissance, Notes)
    VALUES ('{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}')"""
    .format(memberID, civilities, Nom, Prenom, Adresse, ZIP, Ville, tel, mobile, email, nomresponsible, prenomresponsible, Naissance, Notes))
    db.commit()
    db.close

Open in new window



if __name__== "__main__":
    try:
        htmlTop()
        page()
        db,cursor = connectDB()
        memberID = random.randrange(999999,9000000)
        formdata = cgi.FieldStorage()
        civilities = formdata.getvalue('civilities')
        Nom = formdata.getvalue('Nom')
        Prenom = formdata.getvalue('Prenom')
        Adresse = formdata.getvalue('Adresse')
        ZIP = formdata.getvalue('ZIP')
        Ville = formdata.getvalue('Ville')
        mobile = formdata.getvalue('mobile')
        tel = formdata.getvalue('tel')
        email = formdata.getvalue('email')
        nomresponsible = formdata.getvalue('nomresponsible')
        prenomresponsible = formdata.getvalue('prenomresponsible')
        Naissance = formdata.getvalue('Naissance')
        Notes = formdata.getvalue('notes')
        print(memberID, civilities, Nom, Prenom, Adresse, ZIP, Ville, mobile, tel, email, nomresponsible, prenomresponsible, Naissance, Notes)
        db,cursor = connectDB()
        Insertmembers2(db,cursor)

Open in new window



Mysql table structure
error message on submitting form to action page
PythonMySQL Server

Avatar of undefined
Last Comment
Dave Baldwin

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jameskane

ASKER
Fantastic !!!  ..... AS USUAL !!

James
Dave Baldwin

Glad to help.
Your help has saved me hundreds of hours of internet surfing.
fblack61