please i need you to help me on this. i am trying to connect python 3.7 to sqlite.
below is the code
it is showing no error when i run but i am not getting the data into the database. please help me out. thanks
below is the code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import sqlite3 from tkinter import * import tkinter.messagebox root = Tk() root.title( 'Personal Information' ) root.resizable( False , False ) root.geometry( '500x500+400+150' ) ####### connect to the Database############################################ conn = sqlite3.connect( "database.db" ) ###### cursor to move around the Database############################### c = conn.cursor() def add_data(): val2 = Nameentry.get() val3 = locentry.get() val4 = phoneentry.get() if val2 = = ' ' or val3 == ' ' or val4 == ' ': tkinter.messagebox .showinfo ( 'Warning' , 'Please fill out all boxes' ) sql = "INSERT INTO 'myown'( Name,Location,Phone_Number)VALUES (?,?,?)" c.execute(sql,(val2,val3,val4)) conn.commit() tkinter.messagebox .showinfo ( 'Message' , 'Data Added' ) Namelabel = Label(text = 'Name' ,font = ( 'ariel,10,bold' ),fg = 'black' ) Namelabel.place(x = 20 ,y = 110 ) Nameentry = Entry(width = 8 ,bd = 8 ,bg = 'steelblue' ,font = ( 'ariel,10,bold' )) Nameentry.place(x = 100 ,y = 100 ) loclabel = Label(text = 'Location' ,font = ( 'ariel,10,bold' ),fg = 'black' ) loclabel.place(x = 20 ,y = 150 ) locentry = Entry(width = 8 ,bd = 8 ,bg = 'steelblue' ,font = ( 'ariel,10,bold' )) locentry.place(x = 100 ,y = 150 ) phonelabel = Label(text = 'Phone' ,font = ( 'ariel,10,bold' ),fg = 'black' ) phonelabel.place(x = 20 ,y = 200 ) phoneentry = Entry(width = 8 ,bd = 8 ,bg = 'steelblue' ,font = ( 'ariel,10,bold' )) phoneentry.place(x = 100 ,y = 200 ) savebtn = Button(bd = 8 ,font = ( 'ariel,10,bold' ),fg = 'black' ,bg = 'steelblue' ,text = 'SAVE' ,padx = 10 , pady = 10 ,command = add_data) savebtn.place(x = 200 ,y = 300 ) root.mainloop() |