1 navicat自己玩一玩
2 练习题一定要搞懂 照着我的思路一遍遍的看敲
3 熟悉pymysql的使用
4 sql注入产生的原因和解决方法 了解
5 思考:如何结合mysql实现用户的注册和登录功能?
import pymysql
conn=pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
password='123456',
db='day48',
charset='utf8'
)
cursor=conn.cursor(cursor=pymysql.cursors.DictCursor)
def register():
while True:
user=input('your name:').strip()
pwd=input('your pwd>>:').strip()
re_pwd=input('your pwd>>:').strip()
if pwd == re_pwd:
sql='insert into userinfo values(%s,%s);'
rows=cursor.execute(sql,(user,pwd))
conn.commit()
sql = 'select * from userinfo where name = %s and pwd =%s;'
rows = cursor.execute(sql, (user, pwd))
if rows:
print('注册成功')
break
else:
print('注册失败')
cursor.close()
conn.close()
else:
print('两次密码输入不一致')
def login():
while True:
user=input('your name>>:').strip()
pwd=input('your pwd>>:').strip()
sql='select * from userinfo where name = %s and pwd =%s;'
rows=cursor.execute(sql,(user,pwd))
if rows:
print('登录成功')
break
else:
print('登录失败')
cursor.close()
conn.close()
func_dic={
'1':register,
'2':login,
}
def run():
while True:
print('''
1 注册
2 登录
''')
choice=input('>>:').strip()
if choice == 'q':
break
elif choice not in func_dic:
print('没有该编号')
continue
func_dic.get(choice)()
run()
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步