1

I am trying to insert data into database, but here is error:

sqlite-problem-sqlite3-operationalerror-near-where-syntax-error

This is my code:

c.execute(f"INSERT INTO math(qula) WHERE name = '{member.name}' VALUES({saboloo})")

2 Answers 2

0

I suspect that you want to update the column qula of an existing row of the table math and not insert a new row.
Also, it's a good practice to use ? placeholders:

c.execute("UPDATE math SET qula = ? WHERE name = ?", (saboloo, member.name)) 
Sign up to request clarification or add additional context in comments.

Comments

0

To insert data into sqlite3, first you have to import sqlite3 module in the Python standard library. You then connect to the file by passing a file path to the connect (xxxx) method in the sqlite3 module, if the database you passed in the connect method does not exist one will be created at that path and if the database exist it will connect to it.

import sqlite3
con = sqlite3.connect('/path/xxx.sqlite3')

You than have to create a cursor object using the cursor() method

c = con.cursor()

You than Prepare, SQL queries to INSERT a record into the database.

c.execute(f"INSERT INTO math(qula) VALUES({saboloo})").

I hope this one helps. You can also read more from here Python SQLite insert data

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.