Hey everyone! I'm making a website, and was wanting to add a comment box, but don't know the codes. I'm not really new to HTML, but I'm new enough to not know it, and I'd really appreciate like a step by step code thing, not just a copy and paste because I wouldn't really learn it that way. Well, a copy and paste would work but still haha. Thanks all!

Dani AI

Generated

asked for a step‑by‑step comment box. Several replies pointed to quick hosted widgets and one correctly noted that HTML/CSS alone cannot persist comments — a server component or an embed from a provider is required. Hosted widgets are fast to install; rolling a custom solution gives control over storage, moderation and security. Below is a minimal, learnable local approach that complements those suggestions.

A simple HTML form (client side) to collect a name and comment:

<form method="post" action="/comment.php">
  <label>Name <input name="name" maxlength="100"></label>
  <label>Comment <textarea name="comment" maxlength="2000"></textarea></label>
  <input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>">
  <button type="submit">Post</button>
</form>

Server side: accept POST, use parameterized queries and store raw input; escape only when rendering. Example (PHP + PDO):

$pdo = new PDO('mysql:host=127.0.0.1;dbname=site;charset=utf8mb4', 'user', 'pass', [
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);

$stmt = $pdo->prepare('INSERT INTO comments (name, comment, created_at) VALUES (:name, :comment, NOW())');
$stmt->execute([':name' => $_POST['name'] ?? '', ':comment' => $_POST['comment'] ?? '']);

When displaying, encode output:

echo htmlspecialchars($row['name'], ENT_QUOTES, 'UTF-8');
echo nl2br(htmlspecialchars($row['comment'], ENT_QUOTES, 'UTF-8'));

Relevant learning references: MDN on HTML forms (MDN forms guide), PHP PDO prepared statements and htmlspecialchars (PHP PDO docs).

Troubleshooting and security notes: always use prepared statements to prevent SQL injection, encode output to prevent XSS, implement CSRF tokens, store DB in utf8mb4, enforce length limits and rate limits to reduce spam, and consider moderation or CAPTCHA for public sites. OWASP has focused guidance on XSS and CSRF prevention (, CSRF cheat sheet).

Recommended Answers

All 4 Replies

You can try shoutbox...
Just enter my website here http://mypembaca.blogspot.com to see the shoutbox

Please visits my website ya

I use http://disqus.com/

if your just interested in learning how to create a comment box then I would suggest you look into a PHP solution for it. Despite knowing how to create a comment box, I found disqus a very great addition to my site.

Comment boxes are something that requires a programming language, not something you can do completely HTML and CSS. A lot of web frameworks and CMS have comment box options build in that you might find useful as well.

along with those two, i use shoutmix. you can customize what it looks like and then they give you the code. you then pop it into the html and you got it. their website is, http://www.shoutmix.com

Sweet! Thanks for the help everyone, it's much appreciated

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.