I cannot delete a data from my database in Python, SQLite3

I’m coding a program that is about the management of the products in a grocery store. I coded a couple of part of my program but I have started getting an error. As I said on the title, I have a button that is in charge of deleting the selected data. And the error the program gives me:
no such column: SALMON
no such column: COLA

That’s exactly the error I’m getting.
I checked my codes a lot of times but I cannot find the reason why this is being happened.
I’m gonna give you the part of my program that is in charge of deleting the selected data below because of my codes are too long.

Here are my codes:

    def DeleteTheProduct(self):
        question = askyesno("","ARE YOU SURE YOU WANT TO DELETE THE PRODUCT?")
        if question:
            selected_product = self.ui2.ProductTable.selectedItems()
            product_to_be_deleted = selected_product[1].text()
                self.curs.execute("DELETE FROM Products WHERE productname=%s"%(product_to_be_deleted))
                self.ui2.statusbar.showMessage("THE PRODUCT HAS BEEN DELETED.",10000)
            except Exception as error:

>Solution :

There is an error in SQL syntax. You need to quote productname in your query:

"DELETE FROM Products WHERE productname='%s'"

otherwise, it tries to find rows where productname column equals with column with given name, but they doesn’t exist

Leave a Reply