Can Anyone Help Me to solve this i had error sqlite3.OperationalError: near "<": syntax error i think that from the sql but still stucking there
def getProfile(id):
connect = sqlite3.connect('C:///Users///Marvin///Desktop///Opencv-face-detection-python-master///SQL///sql.db')
cur = connect.cursor()
connect.execute("SELECT * FROM user WHERE id="+str(id))
profile=None
for row in cur:
profile=row
cur.close()
return profile
I cannot replicate your error in my testing.
While I was testing your code, I notice a problem with
connect.execute("SELECT * FROM user WHERE id="+str(id))
I think it should be
cur.execute("SELECT * FROM user WHERE id="+str(id))
That works during my testing. Please let me know if this works or not. By changing this, the function returns a result and I was able to get the result.
If you don't mind, I have one extra piece of advice for you. The way you wrote your query is very prone to SQL Injection attacks as shown here . I would recommend you to structure your query in the following way.
cur.execute("SELECT * FROM user WHERE id=?",str(id))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.