Answer the question
In order to leave comments, you need to log in
How to compare a variable with a value in the database?
There is a bot in the cart. I want the bot if a person has already written, then do not save his chat_id, but save the others in a new line. I don't know how to compare them with each other. Tried with different data types. It either does nothing under if
chat_id = str(message.chat.id)
cursor.execute("select * from Table_1 where Chat_id = "+chat_id+"")
row = cursor.fetchall()
print(row) # prints []
if row == "[]":
cursor.execute("insert into Table_1 values ('"+chat_id+"')")
print("Add")
conn.commit()
Answer the question
In order to leave comments, you need to log in
It is better though about data types esteem. It's too early for you to write programs longer than five lines. I can't recommend anything else.
You compare a line with an array
Quote marks from a condition try to remove.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question