0

I'm beginning using GUI . My first project is to do login system that connected to database mysql using easygui in raspberry pi 3. I already do the coding for enter the password but I dont know how to connect it with database while press ok button. While I run the coding, it will be display the password and username at the cmd. I dont know how to set it with database.

This is my coding:

import easygui as eg

msg = "Enter logon information"
title = "Demo of multpasswordbox"
fieldNames = ["User ID", "Password"]
fieldValues = []  # we start with blanks for the values
fieldValues = eg.multpasswordbox(msg,title, fieldNames)

# make sure that none of the fields was left blank
while 1:
  if fieldValues == None: break
  errmsg = ""
  for i in range(len(fieldNames)):
    if fieldValues[i].strip() == "":
      errmsg = errmsg + ('"%s" is a required field.\n\n' % fieldNames[i])
  if errmsg == "": break # no problems found
  fieldValues = multpasswordbox(errmsg, title, fieldNames, fieldValues)
print "Reply was:", fieldValues
001
  • 13,291
  • 5
  • 35
  • 66
  • [How do I connect to a MySQL Database in Python?](//stackoverflow.com/q/372885) – 001 Jul 18 '18 at 04:30

2 Answers2

0

You're creating FieldValues as an empty list that will store your inputs. Inputs are stored in the order of your created fields, in your code:

import easygui as eg

msg = "Enter logon information"
title = "Demo of multpasswordbox"
fieldNames = ["User ID", "Password"]
fieldValues = []  # we start with blanks for the values
fieldValues = eg.multpasswordbox(msg,title, fieldNames)

userID = fieldValues[0]
password = fieldValues[1]
0
from easygui import *
import mysql.connector

TITLE = "Enter logon information"
conn = ""
table = ""

def Login():
    global conn
    conn = mysql.connector.connect(host='localhost',user='pi',password='1234',db='mydb')
    cursor = conn.cursor()

    msg = "Enter logon information"
    title = "Login"
    fieldNames = ["Usercode","Password"]
    fieldValues = []
    fieldValues = multpasswordbox(msg,title,fieldNames)
    usercode, password = fieldValues[0], fieldValues[1]
    sql = "SELECT * FROM `data` WHERE usercode = %s AND password = %s"
    cursor.execute(sql,(usercode,password))
    results = cursor.fetchall()


Login()