Feb-19-2019, 03:03 AM
I am trying to figure out how to use a variable instead of the actual table name in the database statement when using INSERT.
I am using a MenuOption to select a recipe topic. I want the INSERT to database to use the selection chosen as the table name.
Example: If the selection is "Appetizers" from the MenuOption I would want the data in the entry fields to INSERT into that table and like wise for any menu option select to load only to the table name that is selected in the MenuOption.
Any help would be appreciated.
I am using a MenuOption to select a recipe topic. I want the INSERT to database to use the selection chosen as the table name.
Example: If the selection is "Appetizers" from the MenuOption I would want the data in the entry fields to INSERT into that table and like wise for any menu option select to load only to the table name that is selected in the MenuOption.
Any help would be appreciated.
def UpLoad(): selection = var.get() try: c.execute('''INSERT INTO {} VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?).format(selection)''', (Recipe.get(), (Cook_Time.get()), (Serves.get()), (Difficulty.get()), (Ingredient1.get()), (Ingredient2.get()), (Ingredient3.get()), (Ingredient4.get()), (Ingredient5.get()), (Ingredient6.get()), (Ingredient7.get()), (Ingredient8.get()), (Ingredient9.get()), (Ingredient10.get()), (Ingredient11.get()), (Ingredient12.get()), (Ingredient13.get()), (Ingredient14.get()), (Ingredient15.get()), (Ingredient16.get()), (Ingredient17.get()), (Ingredient18.get()), (Ingredient19.get()), (Ingredient20.get()), (Ingredient21.get()), (Ingredient22.get()), (Instruction1.get()), (Instruction2.get()), (Instruction3.get()), (Instruction4.get()), (Instruction5.get()), (Instruction6.get()), (Instruction7.get()), (Instruction8.get()), (Instruction9.get()), (Instruction10.get()), (Instruction11.get()), (Instruction12.get()), (Instruction13.get()), (Instruction14.get()))) conn.commit() except: messagebox.showerror("Error", "Data Base was not able to SAVE") var = tkinter.StringVar(window_3) # initial value var.set('Menu') choices = [ 'Appetizers', 'Beef', 'Bread', 'Cake', 'Chicken', 'Chilli', 'Curry', 'Desert', 'Drinks', 'Egg', 'Fish', 'Pasta', 'Pork', 'Potato', 'Rice', 'Salad', 'Sandwich', 'Sauce', 'Sea Food', 'Slow Cooker', 'Soup', 'Stew', 'Tofu', 'Vegetables'] option = tkinter.OptionMenu(window_3, var, *choices) option.place(x=215, y=120) button = tkinter.Button(window_3, text="Save Recipe", command=UpLoad) button.pack button.place(x=363, y=120)
"Often stumped... But never defeated."