'I creating a receipt generator in python and I fetch data from MySQL to a text area but it's not work. I don't know that where I making the mistake

from tkinter import*

from PIL import Image,ImageTk

from tkinter import ttk

import mysql.connector

from tkinter import messagebox

import time

root=Tk()

root.title("Hotel Management System")

root.geometry("1135x470+225+221")

#====================== Variables ======================
        
var_id=StringVar()

#=====================Function for receipt and Fetch data from mysql ========================

def receipt():


 if var_id.get()=="":

  messagebox.showerror("Error","Please Enter Customer ID",parent=root)

 else:

  conn=mysql.connector.connect(host="localhost",username="root",password="sqlab12",database="management")

  my_cursor=conn.cursor()

  query=("select Ref from customer where Idnumber=%s")

  value=(var_id.get(),)

  my_cursor.execute(query,value)

  row=my_cursor.fetchone()



 if row==None:

  messagebox.showerror("Error","This Number is Not Found",parent=root)

 else:

  conn.commit()

  conn.close()

  date=time.strftime("%d/%m/%Y")

  textarea.insert(END,"Customer Ref:"+row+date)

    


#====================== Title =======================
 
lbl_title=Label(root,text="BILL GENERATE ",font=("time new 
roman",18,"bold"),bg="black",fg="gold",bd=4,relief=RIDGE)

lbl_title.place(x=0,y=0,width=1135,height=50)

#========================== LOGO =====================

img2=Image.open(r"F:\Pictures\VA\Project\Hotel Management System\images\logohotel.png")

img2=img2.resize((100,40),Image.ANTIALIAS)

photoimg2=ImageTk.PhotoImage(img2)

lblimg=Label(root,image=photoimg2,bd=0,relief=RIDGE)

lblimg.place(x=5,y=5,width=100,height=40)

#============================================== RECEIPT =================

F2=Frame(root,relief=GROOVE,bd=5)

F2.place(x=580,y=90,width=530,height=380)

bill_title=Label(root,text="Receipt",font=("arial",15,"bold"),bd=7,relief=GROOVE)

bill_title.place(x=580,y=50,width=530)

scrol=Scrollbar(F2,orient=VERTICAL)      

scrol.pack(side=RIGHT,fill=Y)

textarea=Text(F2,font=("arial",12,"bold"),yscrollcommand=scrol.set) 

textarea.pack(fill=BOTH)

scrol.config(command=textarea.yview)


#============================================== BUTTONS ============================

btn_frame=Frame(root,bd=3,relief=RIDGE)

btn_frame.place(x=6,y=346,width=417,height=42)


#=====================CUSTOMER_ID_NUMBER=================

lbl_cust_id=Label(root,text="Customer ID :",font=("arial",13,"bold"),padx=5,pady=4)

lbl_cust_id.place(x=6,y=250)

enty_id=ttk.Entry(root,width=23,textvariable=var_id,font=("arial",13,"bold"))

enty_id.place(x=140,y=250)

btnReceipt=Button(btn_frame,text="Receipt",command=receipt,font=("arial",11,"bold"),bg="black",fg="gold",width=10)

btnReceipt.grid(row=0,column=0,padx=2,pady=2)

btnPrint=Button(btn_frame,text="Print",font=("arial",11,"bold"),bg="black",fg="gold",width=10)

btnPrint.grid(row=0,column=1,padx=1,pady=2)

btnSave=Button(btn_frame,text="Save",font=("arial",11,"bold"),bg="black",fg="gold",width=10)

btnSave.grid(row=0,column=2,padx=1,pady=2)

btnSend=Button(btn_frame,text="Send",font=("arial",11,"bold"),bg="black",fg="gold",width=10)

btnSend.grid(row=0,column=3,padx=1,pady=2)



root.mainloop()


Solution 1:[1]

You are missing something to insert in place of the %s:

query=("select Ref from customer where Idnumber=%s")

needs to have something like

query=("select Ref from customer where Idnumber=%s" % Idnumber)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lyle Gunderson