Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#!"C:\\Users\\M1032959\\AppData\\Local\\Programs\\Python\\Python36\\python.exe"

import cgi, cgitb
import _mysql
import sys
import logging

print ("Content-Type: text/html")
print ("""
  <TITLE>Bank login</TITLE>
""")

log_fname = "login_Details.log"

logging.basicConfig(filename=log_fname,
                    filemode='a',
                    level=logging.DEBUG,
                    format='%(asctime)s : %(levelname)s => %(message)s',
                    datefmt='%Y-%m-%d %H:%M:%S'
                   )

frmEmp = cgi.FieldStorage()

try:
    conn = _mysql.connect("localhost", "root", "", "bank_details")
    logging.info('connection details:%s',conn)
except Exception as e:
    print ("<br>Connection Error-> e</br>")
    logging.error('connection error: %s',e)
sys.exit()

class UserBankData:
    username = []
    upassword = []    
    def __init__(self):
        username = self.username
        upassword = self.upassword            
    def validateData(self):
        username = frmEmp.getvalue("uname")
        upassword = frmEmp.getvalue("upassword")
        # serch username and password in database
        sql = "SELECT uname,pass FROM login_check"
        conn.query(sql)
        login = 0
        # Store the result set
        all_recs = conn.store_result()
        rec = all_recs.fetch_row()
        while (rec):
          for ename, epass in rec:
            ename = str(ename, 'utf-8')
            epass = str(epass, 'utf-8')
            if(username == ename and upassword == epass):
                login =1
                logging.info("User name and Password is correct")
                break
            rec = all_recs.fetch_row()
        if(login == 0):
            logging.error("User name and Password is not correct.. Please enter proper details")
            print("User name and Password is not correct.. Please enter proper details")
            
obj = UserBankData()
obj.validateData()
conn.close()


What I have tried:

I am new in python and i wrote giving code in python. When i run code it is not giving any error but it not calling class function validateData().
Posted
Updated 17-Jan-18 22:32pm
v2

1 solution

Probably because your call to sys.exit() is not indented, so is not part of the exception handler, but executed immediately after the try/except block.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900