Answer the question
In order to leave comments, you need to log in
Why does deleting one record from the database not work?
What is wrong in the code? You need to remove the selected product from the cart. In the sql query, if I write a specific product, then yes, the deletion is performed, but you need to delete the product that is selected from the basket. Where is the mistake? Is the solution wrong? Who fumbles, tell me how to do it right ... Thank you!
cur.execute(f"SELECT * FROM Корзина_юзера WHERE Юзер = '{user}'")
show_Korzina = cur.fetchall()
print(show_Korzina)
for row in show_Korzina:
print(row[0])
if text == 'Удалить_товар':
if row[0] in show_Korzina:
#Удалить выбранный товар
cur.execute(f"DELETE FROM Корзина_юзера WHERE Товар = '{row[0]}' ")
print ( "Выбраный товар удалён из корзины")
bot.send_message(message.chat.id, f'Товар удалён из корзины')
con.commit() #сохранить изменения
Answer the question
In order to leave comments, you need to log in
What is the composition of the fields in the table Cart_user ? On the screen in row[0] = Nikitich , is that a user?
Here it is more correct to write:
cur.execute(f"SELECT Product_ID , * FROM User_Cart WHERE User = '{user}'")
then it will work:
cur.execute(f"DELETE FROM User_Cart WHERE Product = '{row[0]} '")
DELETE FROM Корзина_юзера WHERE Товар = '{row[0]}' AND Юзер = '{user}'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question