Student feedback form/CRUD app


I’m creating a student feedback form which allows a user to choose answers via st.selectbox. Their answers are then stored in an SQLite database. My code doesn’t seem to have any errors and the database file (student_feedback.db) was successfully created as well as the feedback table. However, when I run the program, my database doesn’t seem to store the values that were input…
I would be incredibly grateful if someone could take a look at my code! :slight_smile:

1 Like

Hey @Vivika_Martini,

First, Welcome to the Streamlit community!!! :partying_face: :tada: :tada: :partying_face: :partying_face: :tada: :partying_face: :tada:

Can you post your code in a code snippet like this:

import streamlit as st 

st.write("A Code Snippet")

You can do this by using 3 backticks (```) on a new line and finishing your code with 3 backticks.

This will allow me to copy your code exactly and try it out on my own computer, so I can try to help you with your question!

Happy Streamlit-ing!


Hey @Marisa_Smith ,

Thank you! :grin:

import streamlit as st

import numpy as np
import pandas as pd

import sqlite3
conn = sqlite3.connect('student_feedback.db')
c = conn.cursor()

def create_table():
    c.execute('CREATE TABLE IF NOT EXISTS feedback(date_submitted DATE, Q1 TEXT, Q2 INTEGER, Q3 INTEGER, Q4 TEXT, Q5 TEXT, Q6 TEXT, Q7 TEXT, Q8 TEXT)')

def add_feedback(date_submitted, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8):
    c.execute('INSERT INTO feedback (date_submitted,Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8) VALUES (?,?,?,?,?,?,?,?,?)',(date_submitted,Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8))

def main():

    st.title("Student Feedback")

    d = st.date_input("Today's date",None, None, None, None)
    question_1 = st.selectbox('Who was your teacher?',('','Mr Thomson', 'Mr Tang', 'Ms Taylor','Ms Rivas','Mr Hindle','Mr Henderson'))
    st.write('You selected:', question_1)
    question_2 = st.slider('What year are you in?', 7,13)
    st.write('You selected:', question_2) 
    question_3 = st.slider('Overall, how happy are you with the lesson? (5 being very happy and 1 being very dissapointed)', 1,5,1)
    st.write('You selected:', question_3)

    question_4 = st.selectbox('Was the lesson fun and interactive?',('','Yes', 'No'))›
    st.write('You selected:', question_4)

    question_5 = st.selectbox('Was the lesson interesting and engaging?',('','Yes', 'No'))
    st.write('You selected:', question_5)

    question_6 = st.selectbox('Were you content with the pace of the lesson?',('','Yes', 'No'))
    st.write('You selected:', question_6)

    question_7 = st.selectbox('Did your teacher explore the real-world applications of what you learnt?',('','Yes', 'No'))
    st.write('You selected:', question_7)

    question_8 = st.text_input('What could have been better?', max_chars=50)

    if st.button("Submit feedback"):
        add_feedback(d, question_1, question_2, question_3, question_4, question_5, question_6, question_7, question_8)
        st.success("Feedback submitted")

if __name__ == '__main__':

1 Like

Hey @Vivika_Martini,

Just saw this so I will work on this now to try and reproduce what your getting there!

1 Like

Hey @Vivika_Martini,

SO! I tried out your code exactly as it is and its working for me! :woman_shrugging:

I was able to create the database and I just read that database into my app with the 3 extra lines of code at the bottom after your submit button if:

if st.button("Submit feedback"):
        add_feedback(d, question_1, question_2, question_3, question_4, question_5, question_6, question_7, question_8)
        st.success("Feedback submitted")

        # lines I added to display your table
        query = pd.read_sql_query('''
        select * from feedback''', conn)

        data = pd.DataFrame(query)


I am using:
macOS Big Sur
Streamlit version: 0.72
Python version: 3.8.5
Anaconda environment

Can you show me what yours looks like when you try to load in your database?



Hi @Vivika_Martini , I also was able to run your code. Except for this symbol “›” in question 4, it runs correctly, and the database file is created. I suspect that in your case could be something related to permissions to write files, but not sure why. Btw, your code is cool :ok_hand:

1 Like

Hiya @Marisa_Smith, that’s awesome, thank you so much!! :smile:
So, when I drop the student_feedback.db file into the SQLite Viewer (SQLite Viewer), the table is just blank… it doesn’t seem to update. However, do I really need to view it externally, could I just create a new app which imports the created database and allows me to visualise the data i.e. create graphs? Essentially what I’m trying to do is get student feedback and then on a separate app analyse it-do you think that’s possible?


Hi @napoles3d , great!!! Yeah it could be that.
Thank you! :blush:

1 Like

Hey @Vivika_Martini,

Try @napoles3d’s removal of the symbol in question 4 and let us know if that works!

I didn’t use the SQLite viewer you did so Im going to try the database your code created on my computer there. see what I get!

It totally works, I’m thinking that the writing file permissions is looking more like the solution! Let us know what you dig up!



Hi @Marisa_Smith , that’s so weird… I still get nothing!

Hi @Vivika_Martini , I know this not the solution to your problem, but could be of help,

Is a Colab Notebook where I put your code. Please try to run it, and let me know if it works for you.

1 Like

Hi, @napoles3d awesome thank you!
So I ran it and it works but then outputs this connection error:

It is a little tricky somethines. That message happens when you try to run in multiple times. It seems weird to me that this happens the first time you run the notebook.
Could you try restarting or running all again??

These are more or less the steps I follow:


1 Like