Get user input and store in a database table


I’m new to streamlit, trying to develop an app for data fusion. Records from two sources will be presented to user and user input will be taken whether a record is a match or not.

Based on an input from user, a column in a database table will be updated with a value either “Match” or “Mismatch”

How to get this value from user and store it in a database table along with name of user and timestamp?

I appreciate your help on this!


Hey @VishalK,

Without any more information on what database or data source you intend to use, I just used mock code below to give you hints on how to do things and make a UI.

import time 

def get_connection_to_db():
    return  # <-- Replace with your db connection method

conn = get_connection_to_db()

def store_in_db(data: dict):
    st.write(data)  # <-- Replace with your db storage method e.g. conn.write(data)

st.header("Data fusion app")
left, right = st.columns(2)
left.subheader("Source 1's record")
left.write("...")  # <-- Replace with your data source 1
right.subheader("Source 2's record")
right.write("...")  # <-- Replace with your data source 2

form = st.form(key="match")
with form:
    name = st.text_input("User name")
    matched = st.selectbox("Choose label", ("Match", "Mismatch"))
    timestamp = time.time()
    submit = st.form_submit_button("Submit")
    if submit:
        store_in_db({"name": name, "matched": matched, "timestamp": timestamp})

CleanShot 2022-09-28 at 15.06.30

See how it looks here

Hope that helps!


@arnaud Thanks a lot!

Will try this code and let you know how it goes.