title: How to get data from HTML using Flask and add it to SQLite?
body: <p>I am trying to get user data using a form and adding it to the <code>SQLite</code> database with <code>SQLAlchemy</code> and <code>Flask</code>. I have tested the same code without <code>SQLite</code> and I was able to add it to a <code>.csv</code> file, however now that I am trying to add a database, I seem to run into issues, can anyone help me understand what is wrong with the code ?</p>
  <p>my model:</p>
  <pre><code>class Submission(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      email = db.Column(db.String(200), nullable = False)
      subject = db.Column(db.Text, nullable = False)
      message = db.Column(db.Text, nullable = False)
  
      def __repr__(self):
          return &quot;&lt;Submission %r&gt;&quot; % self.email
  </code></pre>
  <p>the view function</p>
  <pre><code>@app.route('/submit_form', methods=['POST', 'GET'])
  def submit_form():
      if  request.method == &quot;POST&quot;:
          email_content = request.form[&quot;email&quot;]
          subject_content = request.form[&quot;subject&quot;]
          message_content = request.form[&quot;message&quot;]
          email = Submission(email=email_content)
          subject = Submission(email=subject_content)
          message = Submission(email=message_content)
          try: 
              db.session.add(email)
              db.session.add(subject)
              db.session.add(message)
              db.session.commit()
              return redirect(&quot;thankyou.html&quot;)
          except:
              return &quot;did not save to database&quot;
      else:
          return &quot;something went wrong, try again&quot;
  </code></pre>
  <p>and this is my form</p>
  <pre><code>&lt;form action=&quot;submit_form&quot; method=&quot;post&quot; class=&quot;reveal-content&quot;&gt;
    &lt;div class=&quot;row&quot;&gt;
      &lt;div class=&quot;col-md-7&quot;&gt;
        &lt;div class=&quot;form-group&quot;&gt;
          &lt;input name=&quot;email&quot; type=&quot;email&quot; class=&quot;form-control&quot; id=&quot;email&quot; placeholder=&quot;Email&quot;&gt;
        &lt;/div&gt;
        &lt;div class=&quot;form-group&quot;&gt;
          &lt;input name=&quot;subject&quot; type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;subject&quot; placeholder=&quot;Subject&quot;&gt;
        &lt;/div&gt;
        &lt;div class=&quot;form-group&quot;&gt;
          &lt;textarea name=&quot;message&quot; class=&quot;form-control&quot; rows=&quot;5&quot; placeholder=&quot;Enter your message&quot;&gt;&lt;/textarea&gt;
        &lt;/div&gt;
        &lt;button type=&quot;submit&quot; class=&quot;btn btn-default btn-lg&quot;&gt;Send&lt;/button&gt;
      &lt;/div&gt;
  </code></pre>