In-Depth: Following One Web Form All the Way to the Database

Tutorials often teach the pieces separately: HTML forms here, SQL there. This free in-depth guide follows one small sign-up form through every step, so you can see how the pieces connect. The example uses Python and SQLite, but the journey is the same in any stack.

Stop 1: the form in the browser

<form method="post" action="/signup">
  <input name="email" type="email" required>
  <input name="name" required>
  <button>Sign up</button>
</form>

When the user presses the button, the browser sends the two values to the server in an HTTP request. At this point they are just text from the internet. Treat them as untrusted.

Stop 2: the server receives the request

A web framework, such as Flask in Python, gives your code the values:

email = request.form["email"].strip().lower()
name = request.form["name"].strip()

Here you can check them: is the email present? Is the name a sensible length? Friendly checks here give users clear messages.

Stop 3: the driver sends SQL with placeholders

conn = sqlite3.connect("app.db")
with conn:
    conn.execute(
        "INSERT INTO members (email, name) VALUES (?, ?)",
        (email, name),
    )

The ? marks are placeholders. The driver sends the SQL and the values separately, so whatever the user typed can never change the meaning of the command. This is what protects you from SQL injection. The with conn: block commits the change if everything succeeds.

Stop 4: the database checks its rules

The table was created with rules:

CREATE TABLE members (
  id     INTEGER PRIMARY KEY,
  email  TEXT NOT NULL UNIQUE,
  name   TEXT NOT NULL
);

If the email already exists, the database refuses the insert with a UNIQUE constraint error. Your app checked earlier, but the database is the final guard, even if two people submit at the same instant.

Stop 5: handling the answer

try:
    with conn:
        conn.execute("INSERT INTO members (email, name) VALUES (?, ?)", (email, name))
except sqlite3.IntegrityError:
    return "That email is already registered."
return "Welcome!"

Catch the specific error and show a helpful message rather than a crash page.

Stop 6: reading it back

Later, a page lists members:

rows = conn.execute("SELECT name FROM members ORDER BY name").fetchall()

The rows travel back through the driver to your code, then into an HTML page in the browser.

The whole journey

StopWhereWhat can go wrongDefence
1BrowserBad or malicious inputTreat as untrusted
2Server codeMissing or odd valuesValidation with friendly messages
3DriverSQL injectionPlaceholders
4DatabaseDuplicates, missing dataConstraints
5Server codeCrashes on errorsCatch specific errors
6BrowserShowing raw text unsafelyTemplate escaping

Where next

Each stop has its own page here: placeholders, constraints and reading error messages. Building this small form yourself, end to end, is one of the best exercises a beginner can do.

A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.

This page is a free outline. No downloadable files, paid content, courses or certificates are offered on this site.