I have used this code to use two variables in a single SQL code in Python :
cursor.execute("select * from customers WHERE username=%s and password=%s", (a, b))
but I've got this error :
MySQLInterfaceError: Python type tuple cannot be converted
though I've converted my strings into a tuple like this:
a = tuple(map(str, emaile.split(",")))
b = tuple(map(str, passe.split(",")))
how can I use these two variables in my cursor.execute code?
sj95126
6,9882 gold badges18 silver badges36 bronze badges
2 Answers 2
query = """select * from customers WHERE username=%s and password=%s"""
tuple1 = ("mini", 9000)
cursor.execute(query, tuple1)
Sign up to request clarification or add additional context in comments.
1 Comment
mini5183
Try doing it in a cleaner way step by step, try it, if it doesn't print them and see. It will work :)
cursor.execute("INSERT INTO table VALUES (%s, %s, %s)", (var1, var2, var3))
answered Aug 15, 2022 at 4:28
Sahil Kandroo
1591 gold badge4 silver badges15 bronze badges
2 Comments
Sahil Kandroo
Mohsen Saeidzadeh
Sahil as you see my variables are not in series i need to have an "And" between them so how should i mention them after ","
default
split()stuff, it looks like you are dealing with comma-separated lists of addresses and passwords, but I see nothing dealing with lists in the SQL...https://docs.sqlalchemy.org/en/14/core/tutorial.html#executingusername in (...)which can be tricky with binds. And doesnt work with another list for another var (that password)