What are some potential pitfalls when using PHP to create a guestbook, as seen in the provided code snippet?

One potential pitfall when creating a guestbook in PHP is the vulnerability to SQL injection attacks if user input is not properly sanitized. To prevent this, it is important to use prepared statements or parameterized queries when interacting with the database. This helps to prevent malicious SQL code from being injected into the query.

// Original code snippet vulnerable to SQL injection
$query = "INSERT INTO guestbook (name, message) VALUES ('$name', '$message')";
$result = mysqli_query($conn, $query);
```

```php
// Updated code snippet using prepared statements to prevent SQL injection
$stmt = $conn->prepare("INSERT INTO guestbook (name, message) VALUES (?, ?)");
$stmt->bind_param("ss", $name, $message);
$name = $_POST['name'];
$message = $_POST['message'];
$stmt->execute();
$stmt->close();