← All posts

A guestbook in twelve lines

24 October 2026

The guestbook on this site reads a form, checks two fields, writes one row to the database, and redirects.

Here is the heart of it:

set name to trim of form "name" set message to trim of form "message" if name is not empty and count of message is at least 3 tell database "insert into guestbook (name, message, posted) values (?, ?, ?)" with name, message, now go to "/guestbook?thanks=yes" end

Everything the visitor types is bound as a parameter and escaped on the way out, so there is nothing to get wrong.

The whole blog, list and post, is this
set slug to last of split path by "/"
if slug is "blog"
  set posts to ask database "select * from posts order by posted desc"
otherwise
  set posts to ask database "select * from posts where slug = ?" with slug
end

to show_post post
  show
    <h2><a href="/blog/[slug of post]">[title of post]</a></h2>
    <p>[first of paragraphs of body of post]</p>
  end
end

for each post in posts
  show_post post
end