Comment box?

Status
Not open for further replies.

overlord20

Fully Optimized
Messages
2,308
Location
spokomptan
im a newb at web design and i want to add a comment box to my website. I want a box where they can right there comments. I got that. But is what i cant figure out is how to make the comments appear under the comment box with date and time. can anyone help me? thank you.

here is the code i use for my comment box...

Code:
<form action="/html/tags/html_form_tag_action.cfm" method="get">
  Comments:<br />
  <textarea rows="3" cols="20"></textarea><br />
  <input type="submit" value="Submit" />
</form>

i just want my website to display the comments and what not that are written in the box... thank you :D
 
You're going to need PHP and MySQL to do that.

SQL:
Code:
CREATE TABLE `comments` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`comments` TEXT NOT NULL
)

comments.php
PHP:
<?php

// connect to mysql
$host = 'localhost';
$user = 'root';
$pass = 'root';
$db   = 'dbname';

$connect = @mysql_connect ($host,$user,$pass) or die ('could not connect to database!');
$select  = @mysql_select_db ($dbname) or die ('could not select database!');


// check if POST data has been entered (meaning a comment was entered)

if (isset ($_POST['submit'])) {
	$comment = mysql_escape_string (trim ($_POST['comment']));
	
	// enter the comment to the database
	$sql = mysql_query ("INSERT INTO comments (id,comments) VALUES ('0','".$comment."')");

	echo 'Your comment has been entered successfully!';
} else {
	// POST data wasnt entered, so display the comments and comment form

	// view comments from database
	$sql = mysql_query ("SELECT * FROM comments");
	while ($row = mysql_fetch_array ($sql)) {
		echo $row['comments'].'<br />';
	}

	// display comment form
	echo '<br /><br />
	<form action="comments.php" method="post">
	Comments:<br />
	<textarea name="comment" cols="40" rows="7"></textarea>
	</form>';
}

?>

Uber basic script, but you can build off it.
 
You may also want to add a field for the name of the User posting the comment and then a hidden one for their IP which would help you sleep at night.
 
You may also want to add a field for the name of the User posting the comment and then a hidden one for their IP which would help you sleep at night.

As well as a date, page ID, etc. But, you can customize it however you see fit.
 
Status
Not open for further replies.
Back
Top Bottom