Solved

Python mysql Insert data error

Posted on 2016-08-13
3
93 Views
Last Modified: 2016-08-13
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
0
Comment
Question by:jameskane
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 41754961
In your VALUES section, you have a single quote at the beginning and the end.  MySQL normally expects single quotes around each value, not the whole section.  Try this.
VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}')"""

Open in new window

0
 

Author Closing Comment

by:jameskane
ID: 41754978
Fantastic !!!  ..... AS USUAL !!

James
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 41754999
Glad to help.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
Creating and Managing Databases with phpMyAdmin in cPanel.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question