Solved

Python mysql Insert data error

Posted on 2016-08-13
3
63 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 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
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
Comment Utility
Fantastic !!!  ..... AS USUAL !!

James
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
Glad to help.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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 …

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now