Click here to Skip to main content
15,893,668 members

How to insert data contained in entry widgets on a GUI correctly into an SQL database created in Python?

Member 14147359 asked:

Open original thread
I am using a get method in python to retrieve the contents of entry widgets on a GUI I created, once a user presses a button, to tell the program that they have entered data into the entry widgets. I then append this data to a list and insert it as a record into an sql database created in python. However when I run my code I keep receiving the error shown below.

In the code below the str entry widgets that I use the get method to retrieve data from, have been created earlier in the code.
# declares and defines function that checks that data in the 'Password' and ' Confirm Password' entries match
def MatchingPasswordsValidator(): if str(PasswordEntry.get())!= str(ConfirmPasswordEntry.get()): tkinter.messagebox.showerror("","Please ensure the passwords you enter match") else: # declares list variable UserDetails = []

    # populates list variable
    UserDetails.append(str(FirstNameEntry.get()))
    UserDetails.append(str(SurnameEntry.get()))
    UserDetails.append(str(PasswordEntry.get()))
    UserDetails.append(str(ConfirmPasswordEntry.get()))

    # inserts user's details into the program's database
    c.executemany("INSERT INTO tblUserDetails VALUES(?,?,?,?)",UserDetails)
    # saves changes made to database
    conn.commit()
File "C:\Users\User\Documents\School\CS\Project\Screen2.py", line 135, in MatchingPasswordsValidator c.executemany("INSERT INTO tblUserDetails VALUES(?,?,?,?)",UserDetails) sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 4, and there are 1 supplied.


What I have tried:

I have tried the following ways to solve the problem:

turning the list into a tuple

using a list literal

inserting data as variables into the database rather than as a list
getting the data from entry widgets inserting it into python variables, then I inserted the python variables into a list variable and then tried to insert this list variable into the sql database I created
Tags: Python3.6

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900