user16563726
user16563726

Reputation:

fetchall() returning [] after inserting

I'm using python 3.9.

The program takes 3 inputs (username,password and email) and then hashes the password variable with sha256 and returns it as result.username,password and email get inserted into a table called accounts. It commits the changes and uses cur.fetchall() to print out the table.

import hashlib
import sqlite3
con = sqlite3.connect('users/accounts.db')

print("Sign Up.")
username = input("Input your username : ")
password = input("Input your password : ")
email = input("Input your email: ")

result = hashlib.sha256(password.encode("utf-8"))

cur = con.cursor()
cur.execute("insert into accounts (username, password, email) values(?,?,?)",(username, str(result.digest()), email))
con.commit()

print(cur.fetchall())
con.close()

Upvotes: 0

Views: 690

Answers (1)

Bkid
Bkid

Reputation: 38

You need to perform a SELECT query first before you can fetch.

Upvotes: 1

Related Questions