ich möchte einen eigentlich simplen Login erstellen. Aber irgendwie stelle ich mich dabei doof an. *Kopf kratz*
Das ist das Script:
Code: Alles auswählen
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
from getpass import getpass
import mysql.connector
class MyGridLayout(GridLayout):
# Initialize infinite keywords
def __init__(self, **kwargs):
# Call grid layout constructor
super(MyGridLayout, self).__init__(**kwargs)
# Set columns
self.cols = 1
# Create 2nd grid layout
self.top_grid = GridLayout()
self.top_grid.cols = 2
# Add widgets
self.top_grid.add_widget(Label(text="Benutzer: "))
# Add Input Box
self.name = TextInput(multiline=False)
self.top_grid.add_widget(self.name)
self.top_grid.add_widget(Label(text="Passwort: "))
# Add Input Box
self.password = TextInput(multiline=False)
self.top_grid.add_widget(self.password)
# Add the new top_grid to app
self.add_widget(self.top_grid)
# Create a submit button
self.submit = Button(text="Einloggen", font_size=32)
# Bind button
self.submit.bind(on_press=self.press)
self.add_widget(self.submit)
def press(self, instance):
# Create or connect to DB
# Define DB
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="passwort",
database="quiz"
)
# Create a cursor
c = mydb.cursor()
# Get data from DB
c.execute(f"SELECT superuser FROM users WHERE username={self.name.text} AND password={self.password.text}")
result = c.fetchall()
class MyApp(App):
def build(self):
return MyGridLayout()
if __name__ == "__main__":
MyApp().run()
Allerings gibt es den User in der Datenbank. Und wenn ich statt {self.name.text} direkt "Hans" (nebst entsprechendem Passwort) in die Abfrage schreibe, bekomme ich auch das erwartete Ergebnis (superuser) zurück.mysql.connector.errors.ProgrammingError: 1054 (42S22): Unknown column 'Hans' in 'where clause'
Der Fehler liegt also beim {self.xxx.text}. Aber irgendwie finde ich nicht heraus, was da falsch läuft. Wenn ich das zur Prüfung per print-Befehl in die Konsole ausgeben lasse, steht da genau das, was ich erwarte.
Könnte mir jemand einen Schubs in die richtige Richtung geben?
Liebe Grüße.
System:
Win 10
PyCharm 2022.1.2 Community
XAMPP 3.3.0 (Apache, MySQL)