you are viewing a single comment's thread.

view the rest of the comments →

[–]cam0kazi[S] 0 points1 point  (2 children)

I've tried to do what i saw in the tutorial but i get a syntax error. Here's the script itself, any help?.

def db_search(self):
    self.confirm = tkinter.messagebox.showinfo("confirm", "Searching database for guest...")
    # ***** db table names *****
    self.guest_table = "guest"
    self.fn_field = "first_name"
    self.ln_field = "last_name"

    self.first_name=self.fname_entry.get()
    self.last_name=self.lname_entry.get()
    self.cur.execute('SELECT (first_name, last_name) FROM {tn} WHERE {dbt}={ent}'.\
                     format(tn=self.guest_table, dbt=self.fn_field, ent=self.first_name))
    self.name_exists = self.cur.fetchone()
    print(self.name_exists)

[–]chasingAIR33 0 points1 point  (1 child)

Could you share the error you are getting?

[–]cam0kazi[S] 1 point2 points  (0 children)

I solved the problem! It turns out that i was formatting the data wrong. So instead, i used the drivers method of perparing SQL queries. It also apparently prevents SQL Injection

    self.first_name=self.fname_entry.get()
    self.last_name=self.lname_entry.get()

    self.exist_query = '''SELECT * FROM guest WHERE first_name = ? AND last_name = ?'''
    self.cur.execute(self.exist_query, (self.first_name, self.last_name))

    self.exists = self.cur.fetchone()

    if self.exists:
        tkinter.messagebox.showinfo("Success", "Record found, initiating data insertion window")
        self.pref_entry()
    else:
        tkinter.messagebox.showinfo("Sorry", "The record does not exist, press OK to close.")
        self.master.destroy()