ich habe eine Frage: meine if Abfragen werden nicht berücksichtig, sondern einfach übersprungen. Auch wenn question= 1 TRUE ist, werden die weiteren inputs für name, genre usw. nicht aufgerufen, sondern es springt direkt zum Ende. Wisst ihr wo mein Fehler ist? Ohne if questions funktioniert alles einwandfrei. Ich möchte nur ein Auswahlmenu erstellen, damit der Enduser eine Wahl hat.
Code: Alles auswählen
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="",
database="valorant"
)
mycursor = mydb.cursor()
question= input("enter 1. to make an entry \nenter 2. if you would like to select every \nenter 3. to drop the table ")
if question==1:
name= input("enter the name of your game: ")
genre= input("enter the genre of your game: ")
release_date= input("enter a date in YYYY-MM-DD format: ")
description= input("enter a game description ")
insertSQL= 'INSERT INTO games (name, genre, release_Datum, description) VALUES (%s, %s, %s, %s)'
game = (name, genre, release_date,description) #construct the entry for your table
mycursor.execute(insertSQL, game) #first value is my table, second value my entry
#mycursor.executemany(insertSQL, game) #to insert arrays
elif question ==2:
mycursor.execute ("SELECT * FROM games")
for x in mycursor:
print(x)
mydb.commit() #to save changes in your table
elif question ==3:
mycursor.execute ("DROP TABLE games")