Home > OS >  fetchall() returning [] after inserting
fetchall() returning [] after inserting

Time:12-24

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()

CodePudding user response:

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

  • Related