i am making a bank management system project for school. I have connected to a database containing an employee table. On the homepage, when i click on employee login and submit the correct detail, i want it to open another page containing further info. Instead, nothing happens on clicking submit, it just goes back to the homepage… here is my code, please tell me where i am going wrong :-
import streamlit as st
import mysql.connector
Function to establish database connection
def create_connection():
connection = mysql.connector.connect(
host=“localhost”,
user=“root”,
password=“my_password”,
database=“bank”
)
return connection
def main():
st.title(“Bank Management System”)
# Add two buttons for employee and customer
button_col1, button_col2 = st.columns(2)
if button_col1.button("Employee"):
employee_login()
def employee_login():
st.header(“Employee Login”)
with st.form("Employee Login Form"):
employee_id = st.text_input("Employee ID")
password = st.text_input("Password", type="password")
if st.form_submit_button("Submit"):
if validate_employee_login(employee_id, password):
employee = get_employee_details(employee_id)
show_employee_dashboard(employee)
else:
st.error("Incorrect employee ID or password. Please try again.")
def validate_employee_login(employee_id, password):
# Establish database connection
connection = create_connection()
# Create a cursor object to execute queries
cursor = connection.cursor()
# Prepare the SQL query
query = "SELECT * FROM employee WHERE emp_id = %s AND password = %s"
# Execute the query with the provided values
cursor.execute(query, (employee_id, password))
# Fetch the result
result = cursor.fetchone()
# Close the cursor and database connection
cursor.close()
connection.close()
# Check if a row was returned
if result is not None:
return True
else:
return False
def get_employee_details(employee_id):
# Establish database connection
connection = create_connection()
# Create a cursor object to execute queries
cursor = connection.cursor()
# Prepare the SQL query
query = "SELECT emp_id, name, region FROM employee WHERE emp_id = %s"
# Execute the query with the provided employee ID
cursor.execute(query, (employee_id,))
# Fetch the result
result = cursor.fetchone()
# Close the cursor and database connection
cursor.close()
connection.close()
# Return the employee details
return result
def show_employee_dashboard(employee):
st.sidebar.title(“Employee Details”)
st.sidebar.write(f"Name: {employee[‘name’]}“)
st.sidebar.write(f"Region: {employee[‘region’]}”)
st.sidebar.write(f"Employee ID: {employee[‘emp_id’]}")
# Add buttons for different actions
st.header("Employee Dashboard")
if st.button("Make Transaction"):
# Add the logic for making a transaction
st.write("Make Transaction button clicked!")
if st.button("Provide Investment"):
# Add the logic for providing an investment
st.write("Provide Investment button clicked!")
if st.button("Provide Loan"):
# Add the logic for providing a loan
st.write("Provide Loan button clicked!")
if name == “main”:
main()