J
J
Jalal Nasirov2021-06-10 11:14:06
Python
Jalal Nasirov, 2021-06-10 11:14:06

how to insert variable into python sql query?

There is this code:

sql.execute("UPDATE users SET message = random[0] WHERE id = user[0];")
 db.commit()
Этот код не работает

How to correctly insert random[0] and user[0]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ramis, 2021-06-10
@Best_Loops

sql = "UPDATE `users` SET `message` = %s WHERE `id` = %s"
cursor.execute(sql, (random[0], user[0]))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question