Is there a way to get data from mysql with a variable and be able to use it in an if statement for a login system

In the select statements I need to select the username and password from the data table in my database based on the users input, the input is retrieved from the userget and passget variables. I’m aware that it gets all the data from the username and password tables but I’m unsure on how to make it only get what the user inputs.

def loginpage():
    def login():
        userget = textinput.get()
        passget = textinput2.get()
        
        

        usercheck = mycursor.execute("SELECT `username` FROM `data`")
        u = mycursor.fetchall()
        print(str(u))

        passcheck = mycursor.execute("SELECT `password` FROM `data`")
        p = mycursor.fetchall()
        print(str(p))

        
        if u == userget and p == passget:
            correctscreen = Tk()
            correctscreen.configure(background='yellow')
            correctscreen.title("Correct")
            correctscreen.geometry("300x200")
            labelc = Label(correctscreen, text="Successfully logged in!")
            labelc.pack()
            buttonc = Button(correctscreen, text="Ok", command=correctscreen.destroy)
            buttonc.pack()
            url = 'https://thepugweb.epizy.com/login.html'
            buttonc1 = Button(correctscreen, text="Ok", command=webbrowser.open(url))
        else:
            incorrectscreen = Tk()
            incorrectscreen.configure(background='pink')
            incorrectscreen.title("Incorrect Details")
            incorrectscreen.geometry("300x200")
            labeli = Label(incorrectscreen, text="Incorrect Details Entered")
            labeli.pack()
            buttoni = Button(incorrectscreen, text="Close", command=incorrectscreen.destroy)
            buttoni.pack()

Answer

You can use one SQL statement to get what you want:

def loginpage():
    def login():
        userget = textinput.get()
        passget = textinput2.get()

        mycursor.execute("SELECT 1 FROM `data` WHERE `username`=%s AND `password`=%s", (userget, passget))
        rows = mycursor.fetchall()
        if rows:
            # login successful
            ...
        else:
            # login failed
            ...