How to insert python/kivy input variable into MySQL database

I am having trouble getting a python/kivy varialbe input to load into my MySQL database. When I run the program, there is a kivy GUI input box that opens and asks the user to enter an id, email, and password.

After I enter the requested data, I want to be able to hit the “Submit” button and have those 3 input data fields be populated into my MySQL database into a table called Person. I have already established that Table and put 3 fields into it called “user_name”, “email”, and “password”. There is also a 4th field that auto assigns an auto incremented key, but that is done automatically by MySQL. I know the “Submit” button works properly and I can even print out the inputed data.

The code I am using to have this data submitted into database is mycursor.execute(“INSERT INTO Person(user_name, email, password) VALUES(%s,%s,%s)”,({f”id”}, {f”email”}, {f”password”})). I get an error on this stating _mysql_connector.MySQLInterfaceError: Python type set cannot be converted.

Here is the total code I have written:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import mysql.connector
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
db = mysql.connector.connect(
host="localhost",
user="root",
passwd="root",
database="testdatabase"
)
mycursor=db.cursor()
class MyGridLayout(GridLayout):
# Intialize infinite keywords
def __init__(self, **kwargs):
#Call grid layout contstructor
super(MyGridLayout, self).__init__(**kwargs)
#Set columns
self.cols = 1
#create second grid layout
self.top_grid = GridLayout()
self.top_grid.cols = 2
#add widgets
self.top_grid.add_widget(Label(text="Choose Your User ID: "))
#add input box
self.id = TextInput(multiline=False)
self.top_grid.add_widget(self.id)
#add widgets
self.top_grid.add_widget(Label(text="Enter a Valid Email Address: "))
#add input box
self.email = TextInput(multiline=False)
self.top_grid.add_widget(self.email)
#add widgets
self.top_grid.add_widget(Label(text="Choose a Strong Password: "))
#add input box
self.password = TextInput(multiline=False)
self.top_grid.add_widget(self.password)
#add top grid to app
self.add_widget(self.top_grid)
#create submit button
self.submit = Button(text="Submit", font_size=32,)
#bind button
self.submit.bind(on_press=self.press)
self.add_widget(self.submit)
def press(self, instance):
id = self.id.text
email = self.email.text
password = self.password.text
self.add_widget(Label(text=f"The User ID you entered is: {id} nThe email you entered is: {email} nThe password you entered is: {password}"))
#clear the input boxes
self.id.text = ""
self.email.text = ""
self.password.text = ""
mycursor.execute("INSERT INTO Person(user_name, email, password) VALUES(%s,%s,%s)",({f"id"}, {f"email"}, {f"password"}))
class MyApp(App):
def build(self):
return MyGridLayout()
if __name__ == '__main__':
MyApp().run()
</code>
<code>import mysql.connector import kivy from kivy.app import App from kivy.uix.label import Label from kivy.uix.gridlayout import GridLayout from kivy.uix.textinput import TextInput from kivy.uix.button import Button db = mysql.connector.connect( host="localhost", user="root", passwd="root", database="testdatabase" ) mycursor=db.cursor() class MyGridLayout(GridLayout): # Intialize infinite keywords def __init__(self, **kwargs): #Call grid layout contstructor super(MyGridLayout, self).__init__(**kwargs) #Set columns self.cols = 1 #create second grid layout self.top_grid = GridLayout() self.top_grid.cols = 2 #add widgets self.top_grid.add_widget(Label(text="Choose Your User ID: ")) #add input box self.id = TextInput(multiline=False) self.top_grid.add_widget(self.id) #add widgets self.top_grid.add_widget(Label(text="Enter a Valid Email Address: ")) #add input box self.email = TextInput(multiline=False) self.top_grid.add_widget(self.email) #add widgets self.top_grid.add_widget(Label(text="Choose a Strong Password: ")) #add input box self.password = TextInput(multiline=False) self.top_grid.add_widget(self.password) #add top grid to app self.add_widget(self.top_grid) #create submit button self.submit = Button(text="Submit", font_size=32,) #bind button self.submit.bind(on_press=self.press) self.add_widget(self.submit) def press(self, instance): id = self.id.text email = self.email.text password = self.password.text self.add_widget(Label(text=f"The User ID you entered is: {id} nThe email you entered is: {email} nThe password you entered is: {password}")) #clear the input boxes self.id.text = "" self.email.text = "" self.password.text = "" mycursor.execute("INSERT INTO Person(user_name, email, password) VALUES(%s,%s,%s)",({f"id"}, {f"email"}, {f"password"})) class MyApp(App): def build(self): return MyGridLayout() if __name__ == '__main__': MyApp().run() </code>
import mysql.connector
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button

db = mysql.connector.connect(
    host="localhost",
    user="root",
    passwd="root",
    database="testdatabase"
    )

mycursor=db.cursor()

class MyGridLayout(GridLayout):
    # Intialize infinite keywords
    def __init__(self, **kwargs):
        #Call grid layout contstructor
        super(MyGridLayout, self).__init__(**kwargs)

        #Set columns
        self.cols = 1

        #create second grid layout
        self.top_grid = GridLayout()
        self.top_grid.cols = 2

        #add widgets
        self.top_grid.add_widget(Label(text="Choose Your User ID: "))
        #add input box
        self.id = TextInput(multiline=False)
        self.top_grid.add_widget(self.id)

        #add widgets
        self.top_grid.add_widget(Label(text="Enter a Valid Email Address: "))
        #add input box
        self.email = TextInput(multiline=False)
        self.top_grid.add_widget(self.email)

        #add widgets
        self.top_grid.add_widget(Label(text="Choose a Strong Password: "))
        #add input box
        self.password = TextInput(multiline=False)
        self.top_grid.add_widget(self.password)

        #add top grid to app
        self.add_widget(self.top_grid)

        #create submit button
        self.submit = Button(text="Submit", font_size=32,)
        #bind button
        self.submit.bind(on_press=self.press)
        self.add_widget(self.submit)


    def press(self, instance):
        id = self.id.text
        email = self.email.text
        password = self.password.text


        self.add_widget(Label(text=f"The User ID you entered is: {id} nThe email you entered is: {email} nThe password you entered is: {password}"))

        #clear the input boxes
        self.id.text = ""
        self.email.text = ""
        self.password.text = ""

mycursor.execute("INSERT INTO Person(user_name, email, password) VALUES(%s,%s,%s)",({f"id"}, {f"email"}, {f"password"}))


class MyApp(App):
    def build(self):
        return MyGridLayout()

if __name__ == '__main__':
    MyApp().run()

Can somebody let me know what I am doing wrong here and point me to the solution of getting that variable input data to populate into my MySQL database.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật