私は、PythonプログラムのパスワードをSQLテーブルに保存するパスワードシステムを持っています。ユーザーがtkinterウィンドウでパスワードを変更できるようにしたいのですが、Python変数の値をSQLテーブルの値として使用する方法がわかりません。ここではサンプルコードは次のとおりです。python変数の値をSQLテーブルに挿入
import tkinter
from tkinter import *
import sqlite3
conn = sqlite3.connect('testDataBase')
c = conn.cursor()
c.execute("INSERT INTO info Values('test')")
c.execute("SELECT password FROM info")
password = (c.fetchone()[0])
#Window setup
admin = tkinter.Tk()
admin.minsize(width=800, height = 600)
admin.maxsize(width=800, height = 600)
#GUI
passwordChangeLabel = Label(admin, text="It is recommended to change your password after first login!", font=("Arial", 14))
passwordChangeLabel.pack()
passwordChangeCurrentPasswordLabel = Label(admin, text="Current Password: ", font=("Arial", 11))
passwordChangeCurrentPasswordLabel.place(x=275, y=30)
passwordChangeCurrentPasswordEntry = Entry(admin)
passwordChangeCurrentPasswordEntry.place(x=405, y=32.5)
passwordChangeNewPasswordLabel = Label(admin, text="New Password: ", font=("Arial", 11))
passwordChangeNewPasswordLabel.place(x=295, y=50)
passwordChangeNewPasswordEntry = Entry(admin)
passwordChangeNewPasswordEntry.place(x=405, y=52.5)
passwordChangeButton = Button(admin, text="Submit", width=20)
passwordChangeButton.place(x=350, y=80)
def changePasswordFunction(event):
newPassword = passwordChangeNewPasswordEntry.get()
enteredPassword = passwordChangeCurrentPasswordEntry.get()
if enteredPassword == password:
c.execute("REPLACE INTO info(password) VALUES(newPassword)")
else:
wrong = tkinter.Toplevel()
wrong.minsize(width=200, height = 100)
wrong.maxsize(width=200, height = 100)
Label(wrong, text="Sorry that password is incorrect!", font=("Arial", 24), anchor=W, wraplength=180, fg="red").pack()
admin.bind('<Return>', changePasswordFunction)
passwordChangeButton.bind('<Button-1>', changePasswordFunction)
このコードは、エラーが表示されます:
sqlite3.OperationalError: no such column: newPassword
にはどうすれば適切に新しい入力されたパスワードとパスワードの欄の前の値を置き換えることができますか?
パラメータ化されたクエリに関するドキュメントは読んでいますか? https://docs.python.org/2/library/sqlite3.html –