Use pycharm download pymysql library , Enter the command at the terminal :

pip install mysql

Use pycharm You need to add some data to the database before the write login operation , Such as user name and password

create database pydb;
use pydb;
create table if not exists user(
u_id int primary key auto_increment,
u_name varchar(10),
u_password varchar(40)
)default charset=utf8;

Insert another data into the database

INSERT INTO user(u_name,u_password)VALUES('zhangsan',123456);

Import after download pymysql library

pymysql Common functions of

db = pymysql.connect( parameter list )


# Close the connection

# Commit to database execution
# Roll back : Because of some mistakes , Leading to unsuccessful execution , You can use this statement , Roll back to the state before the error
cursor = db.cursor()
# Returns the cursor object , Specific implementation sql The command requires a cursor object

# Simulate user login 
# Ideas : First, get the user name and password that the user entered , Connect to database , Get query results , Compare the results with the user's input data
import pymysql
u_name=input(' enter one user name :')
u_password=input(' Input password :')
# Get cursor object
sql='''SELECT * FROM user'''
# Get the result of the query
for i in results:
if(name==u_name and pwd==u_password):
print(' Landing successful :'+u_name)
elif(name==u_name and pwd!=u_password):
print(' Wrong password ')
else:print(' The username does not exist ')
except Exception as e:

Test login successful

use python Connect to database to simulate user login

  1. python Initial study Simulate user login

    #!/usr/bin/env python#coding:utf-8''' 2017 year 8 month 19 Japan Simulate user login ,userfile File save Dictionary user name , And password sorryname File save Dictionary Logged in ...

  2. Simulated user login includes registration ——python The first 8 God

    print(' Welcome to shangya dream python learning system '.center(30)) print('******' * 8) flag = True while flag: order = input(''' ...

  3. python Small exercise -- Simulate user login ,(3 Second try , Login success, display login account password )

    Knowledge point use :1. Two ways to format output ---% .formate 2.while The use of recycling , And two ways to get out of the loop ---break( Jump out of the loop ).continue( End this cycle , So let's move on to the next cycle ) 3.if strip ...

  4. Application String Class to implement a simulated user login program

    package Test; import java.util.Scanner; // Simulate user login program // Ideas : // 1. With two String Class receives the user name and password, respectively // 2. Judge the input user name and password ...

  5. Simulate user login and maintain session Simulate user login and maintain session Partially Prepared Products , Not entirely useful import; import ...

  6. python3.0 Simulate user login , Three false locks

    # -*- coding:utf-8 -*- # Demand simulation user login , Login is not allowed for more than three wrong locks     count = 0   #realname passwd Real_Username = &quo ...

  7. xpath Technical analysis xml And the case simulation user login effect

    problem : When using dom4j Query the nodes in the deeper hierarchy ( label , attribute , Text ), More trouble !!! xpath It is in this case that -- It's mainly used to quickly get what you need [ Node object ]. stay dom4j How to use xPath technology 1) ...

  8. jdbc Encapsulate simulated user login

    dao layer Interface package com.qu.dao; public interface ILoginDAO { /** * Simulate user login * Verify user name Is the password correct * select * from ...

  9. scrapy Simulate user login

    scrapy Framework to write three ways to simulate user login : Mode one : carry cookie Sign in , carry cookie Generally requested url For the page after login , obtain cookie Information should be obtained on the page after login ,cookie Parameters should be converted to dictionary form # ...

  10. Simulate user login and maintain session【 turn 】 Simulate user login and maintain session Partially Prepared Products , Not entirely useful import; import ...

Random recommendation

  1. ApexSQLLog Can read only ldf file

    ApexSQLLog Can read only ldf file Need database online The copyright of this article belongs to the author , Shall not be reproduced without the consent of the author .

  2. 【Java A daily topic 】20161221

    package Dec2016; public class Ques1221 { } class Parent{ public void test(){ System.out.println(&quo ...

  3. js Operation array encapsulation

    function OperateArray(array) { this.array = array; } OperateArray.prototype.hasValue = function(val) ...

  4. 【leetcode】Largest Number *

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  5. Android in ListView Detailed explanation ( Two )

    The copyright of this article belongs to csdn noTice501  all , Please indicate the original author and the source of the reprint , To show respect for ! author :noTice501 original text : ...

  6. 【Electron】Electron Introduction to development ( Four ): operation PC End file system

    One . call PC Open local file by default stay main.js in // Open system local file or web page link const {shell} = require('electron'); // Open a local f ...

  7. django Template filter

    filter , Changes in the display of variables One . form : A lowercase letter {{ name | lower }} Two . Series connection : First escape the text to HTML, Then convert each line to <p> label {{ my_text|escape|line ...

  8. solve java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.robolectric.annotation.Config.application()

    Deleting the .gradle folder worked for me too. Odd. Guessing some high level caching going on somewh ...

  9. Java The foundation Java Modifier

    Preface :Java One of the internal mental skills Java Modifier , After reading this, you can tell Java Another step on the road of the great God ( If you have any questions or need information, please contact my button :734999078) Java Language provides a lot of modifiers , It is mainly divided into the following two categories : interview ...

  10. Tomcat monitor 443 Method of port

    When we need to visit the website more safely, we will choose to use https agreement , and https The default port number of the protocol is 443 port , That's why we're asking Tomcat Monitor in 443 The reason for the port , Because monitoring is not 80 Port and 443 Port of web clothing ...