zoukankan      html  css  js  c++  java
  • day48 work

    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()
    
  • 相关阅读:
    CSP-201512
    SCC-Tarjan
    CSP-201509
    Codeforces Round #612 (Div. 2)/A/B/C/D
    CF-Hello 2020/A/B/C
    Anaconda介绍、安装及使用教程
    Linux 新手应该知道的 26 个命令
    Python编码规范:IF中的多行条件
    Python assert 断言函数
    数据结构常见的八大排序算法(详细整理)
  • 原文地址:https://www.cnblogs.com/linqiaobao/p/12842910.html
Copyright © 2011-2022 走看看