Answer the question
In order to leave comments, you need to log in
"not working" sqlite3 database?
The bottom line is, I created a simple database, just to store logins and passwords entered through the console. But, when entering data and following from the output, only the last entered login is displayed, as if I store them not in the database, but in a simple variable. Who can tell me where is my mistake?
PS my code is:
import sqlite3
sql = sqlite3.Connection('enter.db')
c = sql.cursor()
print('Подключение к базе данных проведено успешно!')
c.execute("""CREATE TABLE IF NOT EXISTS users (userlogin TEXT, password INTEGER, cash INTEGER)""")
sql.commit()
userlogin = input('Логин: ')
password = input('Пароль: ')
c.execute("SELECT userlogin FROM users")
if c.fetchone() is None:
c.execute('INSERT INTO users VALUES (?, ?, ?)', (userlogin, password, 0))
else:
print('Такой логин уже занят')
c.execute("SELECT * FROM users")
print(c.fetchall())
Answer the question
In order to leave comments, you need to log in
We read about the basics of sql, specifically here about WHERE, although due to a misunderstanding of the problem, it is better to go through the entire course of the basics.
Who can tell me where is my mistake?
import sqlite3
sql = sqlite3.Connection('enter.db')
c = sql.cursor()
print('Подключение к базе данных проведено успешно!')
c.execute("""CREATE TABLE IF NOT EXISTS users (userlogin TEXT, password INTEGER, cash INTEGER)""")
sql.commit()
userlogin = input('Логин: ')
password = input('Пароль: ')
c.execute("SELECT userlogin FROM users where (?)", (userlogin,))
if c.fetchone() is None:
c.execute('INSERT INTO users VALUES (?, ?, ?)', (userlogin, password, 0))
sql.commit()
else:
print('Такой логин уже занят')
c.execute("SELECT * FROM users")
print(c.fetchall())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question