-1

I am working on a project where i need to update the password column of a user table pointing userid as the primary key, whenever the user reset his/her password. I am passing username and password to update_table function based on the values entered by the user from console and below is my code snippet -

def sql_update_table(conn, username, reset_password):
    c = conn.cursor()
    #value = (username, reset_password)
    #c.execute('''UPDATE user SET password = ? WHERE userid = ? ''', value)
    c.execute('''UPDATE user SET password = reset_password WHERE userid = username''')
    conn.commit()

I tried both case passing values with a tuple as mentioned in # and directly as mentioned without a #. However, for first case, there is no error but the table is not getting updated with the new value of password and for later one i am getting below error -

sqlite3.OperationalError: no such column: reset_password

Please help me to solve this. Thanks in advance !

1

1 Answer 1

0

Can you please try replacing

c.execute('''UPDATE user SET password = reset_password WHERE userid = username''')

with

c.execute('''UPDATE user SET password = ? WHERE userid = ? ''', (username,reset_password))
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you Bindu for your reply. However, I have tried that as well as below. Table is not getting updated. value = (username, reset_password) c.execute('''UPDATE user SET password = ? WHERE userid = ? ''', value)
while printing value, i am getting the updated values in a Tuple format but not sure why its not getting updated in Table
@SameerRanjanSahoo value should be enclosed in parenthesis. please give a try with this c.execute('''UPDATE user SET password = ? WHERE userid = ? ''', (username,reset_password))
Ok, I have tried. Got same result as before. Table is not updated.

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.