老师,我的代码不能实现更新用户的功能。代码反复看了好几遍没看出问题在哪里,请帮忙看看吧,谢谢,谢谢
app.py
#更新用户
elif opt == "2":
page = 1
while True:
os.system("cls")
count_page = __user_service.count_user_page()
result = __user_service.search_list(page)
for index in range(len(result)):
one = result[index]
print(Fore.LIGHTBLUE_EX, "\n\t{}\t{}\t{}".format(index + 1, one[1], one[2]))
print(Fore.LIGHTBLUE_EX, "\n\t--------------------")
print(Fore.LIGHTBLUE_EX, "\n\t{}/{}".format(page, count_page))
print(Fore.LIGHTBLUE_EX, "\n\t--------------------")
print(Fore.LIGHTRED_EX, "\n\tback.返回上一层")
print(Fore.LIGHTRED_EX, "\n\tprev.上一页")
print(Fore.LIGHTRED_EX, "\n\tnext.下一页")
print(Style.RESET_ALL)
opt = input("\n\t请输入操作编号:")
if opt == "back":
break
elif opt == "prev" and page > 1:
page = page - 1
elif opt == "next" and page < count_page:
page = page + 1
elif int(opt) > 0 and int(opt) < 11:
os.system("cls")
user_id=result[int(opt)-1][0]
user_name = input("\n\t新用户名")
password = getpass("\n\t新密码")
repassword = getpass("\n\t确认新密码")
if password != repassword:
print("\n\t两次输入的密码不一致(3秒后自动返回)")
time.sleep(3)
continue
email = input("新邮箱:")
result = __role_service.search_list()
for index in range(len(result)):
one = result[index]
print(Fore.LIGHTGREEN_EX, "\n\t{}.{}".format(index + 1, one[1]))
opt = input("\n\t角色编号:")
role_id = result[int(opt) - 1][0]
opt=input("\n\t是否需要保存(Y/N)")
if opt=="Y" or opt=="y":
__user_service.update_user(user_name,password,email,role_id,user_id)
user_dao.py
#更新用户
def update_user(self,user_name,password,role_id,email,id):
try:
con = pool.get_connection()
con.start_transaction()
cursor = con.cursor()
sql = "update t_user set user_name=%s,password=hex(aes_decrypt(%s,'HelloWorld')),email=%s,role_id=%s " \
"where id=%s"
cursor.execute(sql,(user_name, password, email, role_id,id))
con.commit()
except Exception as e:
if "con" in dir():
con.rollback()
print(e)
finally:
if "con" in dir():
con.close()
user_service.py
#更新用户
def update_user(self,user_name,password,email,role_id,id):
self.__user_dao.update_user(user_name,password,email,role_id,id)
正在回答
- 参与学习 人
- 提交作业 625 份
- 解答问题 2669 个
数据库作为企业储存和管理数据的根本,掌握数据库是每个开发工程师必备的技能,本阶段带你学会用Python操作MySQL、Redis和MongoDB三大主流数据库。夯实数据库基础。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星