Solved

Python mysql Insert data error

Posted on 2016-08-13
3
108 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Could you point what are the possible solutions to solve this XAMPP port 80 problem? 9 54
java mysql insert application 14 47
MYSQL responding very slow 3 51
IDE for Python 5 73
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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 while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

730 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