Answer the question
In order to leave comments, you need to log in
How to edit entries in sqlite via python?
I'm trying to add the ability to add a phone number in the bot, I can't figure out how to edit the phone_number field .
db = sqlite3.connect('Товар.db', check_same_thread=False)
sql = db.cursor()
@bot.message_handler(commands = ['number'])
def Запрос_номер_телефона(message):
zapros = sql.execute(f"SELECT Номер_телефона FROM Пользователи WHERE user_id = '{message.from_user.id}'")
number = sql.fetchone()
print('number', number)
if number is None:
bot.send_message(message.chat.id, 'Хотите оставить номер телефона?', reply_markup = markup_reg1)
if message.text == 'Оставить номер':
bot.send_message(message.chat.id, 'Отправить номер из телеграм или написать?', reply_markup = markup_reg2)
if message.text == 'Номер из телеграм':
db.execute("UPDATE Пользователи Номер_телефона = ?",
(message.contact.phone_number))
elif message.text == 'Ввести':
bot.send_message(message.chat.id, 'Вводите')
db.execute("UPDATE Пользователи Номер_телефона = ?",
(message.text))
db.commit()
print(f'Номер пользователя {message.from_user.username} зарегистрировын')
elif message.text == 'Нет':
bot.send_message(message_handler.chat.id, 'Хорошо')
else:
bot.send_message(message.chat.id, 'Номер телефона уже зарегистрировын.')
bot.polling(none_stop = True, interval = 0)
bot.polling(none_stop = True, interval = 0)
Answer the question
In order to leave comments, you need to log in
Do I understand correctly, you have a flat table Users, where each user has a row, each user has attributes (columns) user_name, user_id, Name, Phone_number
Then in the row
db.execute("INSERT INTO Пользователи (Номер_телефона) VALUES (?)",
(message.text))
you are trying to add a row, but you need to update an already created row, similar to the update from the previous branch. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question