Answer the question
In order to leave comments, you need to log in
How to teach a chat bot in telegram to perceive letters?
The bot in the cart when issuing details inside the bot can only accept numbers, that is, an
error
pops
up for any letter, please help fix
it ) ')
q = connection.cursor()
try:
q.execute("update config set bitcoin = " + str( new_bitcoin ) + " where id = 1")
connection.commit()
q.close()
connection.close()
bot.send_message(message.chat.id, 'Success!', reply_markup=keyboards.admin)
except:
bot.send_message(admin, 'Error', reply_markup=keyboards.admin)
Answer the question
In order to leave comments, you need to log in
I will send you
'';drop table config;select bitcoin from config
And the config table will be deleted. This is called SQL injection .
You do not wrap the string in quotes, of course, nothing good will come of it. In the case of numbers, of course, the query without quotes succeeds. But in general, this is the wrong way to use SQL, since any quote will break it, and carefully prepared text (I gave an example) will generally cause the wrong query that was planned.
Correct use of placeholders:
q.execute("UPDATE config SET bitcoin=? WHERE id=?", (new_bitcoin, user_id))
q.execute("update config set bitcoin = " + str( new_bitcoin ) + " where id = 1")
update config set bitcoin = 1234 where id = 1
update config set bitcoin = foobar where id = 1
update config set bitcoin = 0; -- where id = 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question