# PHP PostgreSQL guestbook

A PHP guestbook collects names and notes, shows every message with its time, and keeps them through new deployments. Tokay runs the page as one Web Service with a managed PostgreSQL database.

Start here when you want saved data without bringing in a full PHP framework. The page, form handling, and database queries all live in `index.php`, so you can follow the complete request in one place.

## Facts

- Runtime: PHP
- Framework: None
- Service types: Web Service
- Resources: PostgreSQL
- Required secrets: None

## What it does

The guestbook opens with a welcome note and a form for your name and message.

Press **Sign the book** and your entry appears at the top with a UTC timestamp. Refresh the page whenever you like and the database keeps it in place.

If either field is empty, the page explains what is missing instead of writing an incomplete entry.

## Deploy it

Bring this folder to Tokay any way you like. Paste or upload it in the dashboard, push it with git, or hand it to your AI agent along with [our agent instructions](https://app.tokay.io/llms.txt). Tokay figures out the rest.

Working in Claude, ChatGPT, VS Code, or another MCP client? Connect the [Tokay MCP server](https://tokay.io/docs/platform-mcp) and ask your agent to deploy this example. It signs in through your browser, so there is no token to paste.

New to Tokay? The [getting started guide](https://tokay.io/getting-started) walks you through your first deploy.

## Finish setup in Tokay

The guestbook needs PostgreSQL to keep its messages. Tokay has already prepared the database setup based on the app. You only need to confirm where `DATABASE_URL` should point.

1. Choose **Environment** from the guestbook Service.
2. Find `DATABASE_URL` under **From your infrastructure**.
3. Choose **Confirm database**.
4. Keep the suggested `app` name.
5. Choose **Confirm**.

After `DATABASE_URL` reaches **Good to go**, finish the deployment tracker. Tokay creates the database and gives the private connection to the app. Use **Go Live** if the tracker shows it, then open the guestbook from the Service's live URL.

## Try it

1. Sign the book and refresh the page to confirm your note remains.
2. Change a piece of page copy, then deploy again.
3. Open the updated page. Your note is still there because PostgreSQL lives beyond the app release.

## How it works

Wondering who creates the table? The app does that on its first database connection, then uses prepared statements for every submitted message. Tokay supplies the private PostgreSQL connection through `DATABASE_URL`, so its password never appears in your code.

## Secrets

You do not need to create a secret. Tokay supplies `DATABASE_URL` when you confirm the managed PostgreSQL database.

## Grow from here

Try the [Laravel event space booking app](/examples/php-laravel-postgres-event-space-booking) when you want a full framework, migrations, and scheduled reminders.

## Source files

- [.htaccess](https://tokay.io/examples/src/php-postgres-guestbook/.htaccess)
- [index.php](https://tokay.io/examples/src/php-postgres-guestbook/index.php)

## Download and source

- [Download the complete project](https://tokay.io/examples/downloads/php-postgres-guestbook.zip)
- Last updated: 2026-07-31
- Example revision: `52c7b7f`
- [View this revision on GitHub](https://github.com/tokayio/tokay-examples/tree/52c7b7ffd52e157375b08f1f11ff4fbe6c498642/php-postgres-guestbook)
- [Deploy an app with a Postgres database](https://tokay.io/use-cases/deploy-app-with-postgres)
