Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown Column in Where Clause Python

mycursor.execute("SELECT PK FROM customers WHERE name = %s" % customer)

Customer is a string.

I am new at MySQL and i'm doing an app in python and i have a problem with WHERE clause. This code generates this error:

Unknown column 'Tomas' in 'where clause'.

Tomas is the name i want to find in my database.

My database looks has atributes: PK, name, surname, age, contact and 3 instances which one of them is Tomas. What am i doing wrong ?

like image 995
Tomáš Rončák Avatar asked Oct 18 '25 11:10

Tomáš Rončák


1 Answers

You might want to have the name compared as a string instead of another column which is what i think mysql is doing. Try this

mycursor.execute("SELECT PK FROM customers WHERE name = `%s`" % customer)

NOTE: The string formatter is enclosed in backticks.

like image 183
TheMonarch Avatar answered Oct 20 '25 02:10

TheMonarch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!