← All Lessons Student Handout →

CiTi · Computer Coding · Year One · Unit 4

My First Admin

The index, add, and edit pattern behind every admin we build

Program Computer Coding: Year 1
Unit 4: Building Data-Driven Websites & Client Management
Duration Two class periods (~55 min each)
Grouping Individual build, pair testing
Project AMP State Admin

Essential Question

From the Year 1 curriculum map
What purposes do databases serve? What distinguishes relational databases?

Curriculum Map Alignment

From Yr 1 curriculum

Concept / Knowledge / Content

  • Functional database concepts
  • Relational database structure: primary and foreign keys
  • Server-side technology for form processing

Skills / Tasks

  • Create accessible forms
  • Connect HTML forms to server-side scripts

Program Connections

Skills & Portrait alignment

Program Skills: What I’m Building Toward

Hands-On:

#4 Design a relational database
#5 Write and execute database queries
#7 Validate and debug my own work

Professional:

#7 Treat a mistake as data, not failure
#9 Document as you go

NYS Portrait of a Graduate

Academically Prepared Critical Thinker

Guaranteed & Viable Curriculum Framework

3 Dimensions for this lesson

Integrated Academic Knowledge

Following data from a form, through a server, into a file, and back onto a page. Keys that identify one record and point at another.

Employability Skills

Reusing one pattern across many jobs, testing with awkward real data, and checking the file, not just the screen.

Technical Skills

Building a list page, an add form that runs [append], and an edit form that prefills a record and runs [replace]: the three files every admin we build is made of.

Learning Intention

“Unwrapped” from the standard

Students will build a three-page admin for their state table, learning the index, add, and edit pattern used for every table in every admin we build.

Success Criteria

  • I can build an index page that lists every record in a table.
  • I can build an add form whose fields send what the database needs.
  • I can explain each piece of an [append] and why typed text is wrapped in [url].
  • I can pass a record’s SKU in a link and use it to find that record.
  • I can prefill an edit form, including the right option in a select.
  • I can explain how [replace] picks which record to change.

Authenticity Continuum

Where this lesson sits
Instruction & Skill Practice
Teacher-Designed Simulation
Realistic Industry Task
Authentic Audience / Client
Product, Service, Impact, Solution

The admin is a real piece of the Aimee Mohr site: a state added here shows up in the contact form menu from the last lesson.

Materials & Prep

  • Student handout (y1-u4-l7-so). Students need their amp folder with state.db, country.db, and the working contact menu from Y1-U4-L5.
  • Teacher reference: the state admin on the teacher AMP site, /citi/coding/2027/ajm/amp/25admin25/state/ (behind the admin login).
  • For the Day 2 demo only: a copy of edit.html pointed at a throwaway copy of state.db.
  • All code in this plan and the handout is drawn as a picture by /curriculum/js/codelock.js. It cannot be selected or copied, and the code text is not in the page source. The handout shows partial code with pink blanks.

The Admin Pattern

Both days

Every table gets one folder with three files. This is the routine for every admin we build, so name it out loud each time.

FileJobKey tag
index.htmlLists every record. No form: it links to add.html and edit.html[search]
add.htmlBlank form; saves a new record[append]
edit.html?skuvar=1038Filled-in form; saves changes to one record[replace]

First years keep these separate: the list never holds a form. Its + Add a state link opens add.html, where the form lives. Both forms use action="[thisurl]", so each posts back to its own page with no file name typed. [thisurl] leaves off the ?skuvar= part, which is why edit needs the hidden input. The processing block sits at the top, right after vars.inc. A plain visit skips it and shows the form; a submit runs it, saves, and redirects to the list. Students use 27admin27/state/ in their amp folder.

Day 1: index.html

Period 1
27admin27/state/index.html (inside the content div)

Nothing new: it is the Search Lab loop from L5 with table rows. All 101 records list. An admin shows everything, inactive records included; the public page filters on status. The Country column uses [lookup]: find the row in country.db whose SKU matches this state’s R_COUNTRY and print its TITLE. Same foreign key as L5, one tag instead of a nested search.

Day 1: add.html

Period 1
The form

Inputs use f_ names so they cannot collide with field tags. The hidden action input is what the processing block checks. The country option sends [SKU], because R_COUNTRY stores the country’s SKU.

The processing block, at the top of add.html
PieceJob
[showif [action]=add]Only runs when the form was sent. A plain visit skips it and shows the form.
[append db=...]Adds one new line (record) to the end of the database.
autonumber=SKUWebDNA fills in the SKU: the highest one so far, plus 1.
FIELD=valueOne pair per field. The name must match the .hdr exactly.
&Goes between pairs. This is how WebDNA knows where one value ends.
[url]...[/url]Wraps anything a person typed, so an & in it cannot cut the value off.
[!] [/!]Hides the line returns, so each pair can sit on its own line.
STATUS=[f_status]From the status menu. Menu values are never typed, so no [url].
[closedatabase]Saves to the file now. The footer never runs, because...
[redirect index.html]...the browser is sent back to the list, which shows the new record.

[closedatabase] is here because [redirect] ends the page, so the footer’s close never runs.

Day 2: edit.html

Period 2

Add the Edit column to the index: <td><a href="edit.html?skuvar=[SKU]">Edit</a></td>. The SKU rides in the URL as skuvar. Never name it sku: it would collide with the [SKU] field tag inside a search.

The form (Abbreviation input left out: same as Full name)

The whole form sits inside a search for that one SKU, so every field tag is that record. [input] makes the value safe inside quotes. The country select runs a second search, and inside it [SKU] means the country, so the state’s R_COUNTRY is saved into [statecountry] first: the same trick as [countrysku] in L5.

The processing block, at the top of edit.html
[append] (add.html)[replace] (edit.html)
Does whatAdds a new recordChanges an existing record
Which recordA new one at the endEvery record that matches its search
SKUautonumber=SKU makes oneeqSKUdatarq=[skuvar] finds one
STATUSFrom the menu, Active firstFrom the menu, prefilled with selected

The Tricky Parts

All tested on our server 2026-11-15

1No [url], and the value is cut at the &

Saving Trinidad & Tobago without [url] stored only Trinidad . With it, the full name was saved.

2A missing & glues two fields together

Without the & after the name, TITLE was saved as No AmpCODE=NM and CODE was blank.

3A misspelled field name is dropped silently

TITEL= in the append saved the record with an empty name and no error.

4No autonumber, no SKU

Without autonumber=SKU the record was saved with an empty SKU. Its Edit link is skuvar= and opens a page with no form.

5No hidden action, nothing happens

Without action=add the form just reloads empty. Nothing is saved and there is no error.

6No hidden skuvar, nothing changes

The edit page redirected as if it had saved, but no record changed.

7Quotes break the edit form without [input]

A name with " in it printed as value="Trinidad & "Tobago"": the box shows only Trinidad &, and the next save loses the rest.

8No selected, the state moves country

Without the [showif], no option is marked selected, so every state’s menu opens on Canada, the first option. One careless save moves New York to Canada.

9[replace] changes every match

With eqR_COUNTRYdatarq=1000 in place of the SKU search, one save rewrote every US record as Alaska2: all 56 in the full table. Demo this on a copy, never on student data.

10Plain line returns did not break it

In our test the append still worked with real returns in place of [!] [/!]. Teach the comment as the house style that keeps the pairs readable, not as a fix.

Teacher Watch List

  • Check the file, not just the page. Several mistakes still redirect to the list like nothing went wrong. Have students open state.db in CyberDuck after each test.
  • Field names in the append must match the .hdr. Form names (f_title) and field names (TITLE) are different on purpose.
  • The processing block goes at the top, before header.inc.
  • Every [showif], [search], and [founditems] closes. On edit.html there are two searches; indent and count.
  • Test with the contact form. A state added with status 1 should appear in the L5 menu under the right country.

Lesson Flow

Two periods, ~55 min each
TimePhaseWhat happens
Day 1: index and add
5 minHookOn the teacher admin, add a made-up state. Open the AMP contact form: it is in the menu. “No one opened the database file.”
5 minThe PatternDraw the three files and the arrows: list to add, add saves and returns to list.
15 minPart AMake the folder and index.html. All 101 records should list.
10 minPart BBuild the add form. Submit it now: nothing saves yet. Ask why.
15 minPart CTake the append apart piece by piece, add it, and add Trinidad & Tobago. Open state.db to see the new line.
5 minBreak ItPairs run experiments 1 and 2. The rest are for early finishers.
Day 2: edit and replace
5 minPart DAdd the Edit links. Hover them: each URL carries a different SKU.
20 minPart EBuild the edit form and check that every field fills in, the country and the status especially.
15 minPart FAdd the replace and fill in the comparison table together. Then the teacher demo: a wrong criterion on a copy, and every US state changes.
10 minBreak ItExperiments 6 and 7, then the rest.
5 minExit TicketCheck-in and exit ticket.

Assessment

Formative: live check of 27admin27/state/: the index lists all records with country names; adding Trinidad & Tobago saves the full name; editing a state prefills every field, the country and status included, and the save shows on the index and in the contact menu.

Exit ticket (completion-graded): what [url] protects, and how [replace] knows which record to change.

Extension: show Active or Inactive on the index instead of 1 or 0, and make the record count say 1 record when there is only one.