php comment system for my website?

  • Thread starter Thread starter Tommy Z
  • Start date Start date
T

Tommy Z

Guest
i need an easy php code for a comment system for my site. I dont want anything already done, i wanna code it myself, to learn php. I got started by coding this:

<div class="main">
<div class="commentContainer">
<div class="comment">
<p class="user">User: <?php echo $_POST["name"]; ?></p>
<br />
<p>Comment: <?php echo $_POST["comment"]; ?></p>
</div>

<div class="commentForm">
<form method="post">
<table>
<tr>
<td>
Name:
<br />
<input type="text" name="name" value="Anonymous" />
</td>
</tr>
<tr>
<td>
Comment:
<br />
<textarea name="comment"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</table>
</form>
</div>
</div>

,but it doesn't save the comment, and it only allows one comment on it, i need help fixing this, btw i want a short tutorial or explanation, not links or downloads. and my site can run php and allows mysql so thats no issue
do i need anything else, because my comments dont save
 
1. You'll need PHP code to store the comments somewhere, probably in a database. So add a form Action to something like comment_add.php.

2. To write the comments on the web page, you'll need to query this information source and loop through the results. It will look like this:

<?php
//... add DB connection code here

$sql = "select * from comments";
$result = mysql_query($sql, $conn1);

foreach ($row = mysql_fetch_assoc($result))
{

?>

<p>Comment: <?php echo $row['comment']; ?></p>

<?php

} // foreach

?>

Good luck!
 
Back
Top