I am creating a form to allow users to edit a database entry. So what happens here is that they will input an index and then the code would use that index to do an sql query for that rowid (returns a tuple). I would then use the tuple to prefill the fields for them to edit. However I am getting unboundlocal error on the variable i assign the tuple to.
if 'num' not in st.session_state: st.session_state.num = 0 if st.session_state.num == 0: with st.form("input index"): index_input = int(st.number_input("Input index you want to edit") index_button = st.form_submit_button(label = "Index to edit") if index_button: editable_row = sqlquery(index_input) #rowid query function st.session_state.num += 1 if st.session_state.num == 1: with st.form("Form to edit"): option1 = st.selectbox("Selections", selections, index = selections.index(editable_row)) . #other lines of streamlit inputs that calls "editable_row" sliced sql data . . . edit_data = st.form_submit_button("Edit data") if edit_data: change_data() #just a function that does replace in sql del editable_row #I thought this would solve it but it didnt st.session_state.num -= 1
Some extra information that this block of code is inserted as a function on my main streamlit page.