0

all! I'm doing the final project, and I have a form whose contents I'm trying to submit to a database.

My python code is:

@app.route("/Contact.html", methods=["GET", "POST"])
def Contact():
  if request.method == "POST":

    name = request.form.get("name")
    artist = request.form.get("artist")
    email = request.form.get("email")
    subject = request.form.get("subject")
    message = request.form.get("message")

    db.execute("INSERT INTO Clients (Name, Band, Email, Subject, Message) VALUES (:name, :artist, :email, :subject, :message)",
            Name=name, Band=artist, Email=email, Subject=subject, Message=message)

    return render_template("Contact.html")

  else:
    return render_template("Contact.html")

HTML is:

<div class="Contact">
<form action="/Contact.html" method="post">
  <label for="name">Name<p6>*</p6>:</label><br>
  <input type="text" id="name" name="name" required><br>

  <label for="artist">Artist/Band Name:</label><br>
  <input type="text" id="artist" name="artist"><br>

  <label for="email">Email<p6>*</p6>:</label><br>
  <input type="text" id="email" name="email" required><br>

  <label for="subject">Subject<p6>*</p6>:</label><br>
  <input type="text" id="subject" name="subject" required><br>

  <div class="Messageboy">
  <label for="message">Message<p6>*</p6>:</label><br>
  <textarea id="message" name="message" required></textarea>
  </div>
  <div class="Submit">
  <input type="submit" value="Submit">
  </div>
  </form>
</div>

I'm receiving an error message saying:

RuntimeError: missing value for placeholder (:name)
INFO:werkzeug:192.168.239.158 - - [15/Jun/2020 21:33:04] "POST /Contact.html HTTP/1.0" 500 -

I'm having issues resolving this problem, so any help to point me in the right direction would be appreciated!

0

Ended up taking some time away from the computer, and came up with the answer!

I was setting the values of the placeholders to the SQL column titles rather than the variables whose form I requested above.

Fixed:

db.execute("INSERT INTO Clients (Name, Band, Email, Subject, Message) VALUES (:name, :artist, :email, :subject, :message)", name=name, artist=artist, email=email, subject=subject, message=message)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .