I was using the SELECT method in a function. I tried to Select all the rows where "First_Name," a column, is equal to "FirstName," a variable. However, it gives me an error saying that "FirstName" is not a column. I have no idea how to fix this issue. I have copy-pasted the SELECT statement below.
c.execute('SELECT * FROM AccountLists WHERE First_Name = FirstName AND Last_Name = LastName')
Andrej Kesely
196k15 gold badges60 silver badges105 bronze badges
1 Answer 1
You need use ? notation, like this:
c.execute('SELECT * FROM AccountLists WHERE First_Name=? AND Last_Name=?', (FirstName, LastName))
The ? is a placeholder that you use wherever you want to use a value and then provide a tuple of values as the second argument to the cursor’s execute() method.
answered Jul 19, 2018 at 17:32
Andrej Kesely
196k15 gold badges60 silver badges105 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Ansh Kumar
Thank you so much for this information. However, I have found another problem. I used the exact same code but removed the last name portion so the statement looks like: c.execute('SELECT * FROM AccountLists WHERE First_Name=?', (FirstName))
Andrej Kesely
@AnshKumar You forgot put "
," after FirstName - to create a tuple: c.execute('SELECT * FROM AccountLists WHERE First_Name=?', (FirstName, ))default