Solved

Python mysql Insert data error

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
First name pregmatch 11 36
linux crontab output 3 66
mysql left join sentence 7 35
How does this Python sort work? 5 65
This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
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 …

911 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

20 Experts available now in Live!

Get 1:1 Help Now