Guestbook Html - Ms Access
| Field Name | Data Type | Description |
|---------------|----------------|---------------------------------|
| id | AutoNumber | Primary key, incrementing |
| name | Short Text (50) | Visitor’s name |
| message | Long Text | The guestbook entry |
| timestamp | Date/Time | Default value: Now() |
| ip_address | Short Text (45) | Optional, for basic spam control|
Save the table. That’s it for the database side.
<%@ Language=VBScript %> <% Dim name, email, website, message, ip, conn, sqlname = Trim(Request.Form("name")) email = Trim(Request.Form("email")) website = Trim(Request.Form("website")) message = Trim(Request.Form("message")) ip = Request.ServerVariables("REMOTE_ADDR")
' Basic validation If name = "" Or message = "" Then Response.Write "Name and Message are required. <a href='javascript:history.back()'>Go back</a>" Response.End End If
' Optionally filter bad words or spam
Set conn = Server.CreateObject("ADODB.Connection") conn.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Server.MapPath("/data/guestbook.accdb")
sql = "INSERT INTO tblGuestbook (Name, Email, Website, Message, IPAddress, DatePosted, Approved) VALUES (" sql = sql & "'" & Replace(name, "'", "''") & "'," sql = sql & "'" & Replace(email, "'", "''") & "'," sql = sql & "'" & Replace(website, "'", "''") & "'," sql = sql & "'" & Replace(message, "'", "''") & "'," sql = sql & "'" & ip & "'," sql = sql & "Now()," sql = sql & "False)" ' Requires admin approval
conn.Execute sql conn.Close Set conn = Nothing
Response.Write "<h2>Thank you, " & Server.HTMLEncode(name) & "!</h2>" Response.Write "<p>Your message has been submitted and will appear after moderation.</p>" Response.Write "<a href='guestbook.html'>Back to Guestbook</a>" %>ms access guestbook html
Security note: We use
Replace(name, "'", "''")to prevent SQL injection. Better yet – use parameterized queries.
Creating a guestbook with MS Access and HTML is a perfect "Hello World" project for database-driven websites. It demystifies the relationship between the Front End (HTML), the Back End (ASP/Scripting), and the Data Storage (Access). While modern developers might opt for SQL Server, MySQL, or NoSQL databases, the logic remains exactly the same as it was in the golden era of the web.
The HTML file serves two purposes: it displays existing entries and provides a form for new ones. | Field Name | Data Type | Description
File: index.html (or index.asp if using the Classic method below)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>My Access Guestbook</title> <style> body font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; .entry border-bottom: 1px solid #ccc; padding: 10px 0; .entry h3 margin: 0; color: #333; .entry small color: #666; .form-group margin-bottom: 15px; label display: block; font-weight: bold; input, textarea width: 100%; padding: 8px; box-sizing: border-box; button padding: 10px 20px; background-color: #007BFF; color: white; border: none; cursor: pointer; button:hover background-color: #0056b3; </style> </head> <body><h1>Guestbook</h1> <!-- Section to Display Entries --> <div id="guestbook-entries"> <!-- Database records will be looped here by the server script --> <p>Loading entries...</p> </div> <hr> <!-- Section to Submit New Entry --> <h2>Sign the Guestbook</h2> <form action="add_entry.asp" method="POST"> <div class="form-group"> <label for="name">Name:</label> <input type="text" id="name" name="name" required> </div> <div class="form-group"> <label for="email">Email:</label> <input type="email" id="email" name="email" required> </div> <div class="form-group"> <label for="comments">Message:</label> <textarea id="comments" name="comments" rows="4" required></textarea> </div> <button type="submit">Submit Entry</button> </form>
</body> </html>