What are common pitfalls when outputting database records individually in PHP, such as in a guestbook format?

One common pitfall when outputting database records individually in PHP, such as in a guestbook format, is not properly escaping the data before displaying it. This can lead to security vulnerabilities like SQL injection attacks. To solve this issue, always use prepared statements or escape functions like mysqli_real_escape_string to sanitize the data before outputting it.

// Assume $row is an associative array containing the database record

echo "<div>";
echo "<p>Name: " . htmlspecialchars($row['name']) . "</p>";
echo "<p>Message: " . htmlspecialchars($row['message']) . "</p>";
echo "</div>";