954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Comment Box

Hi Everyone,

I am very new to web design and just starting to get the basics of CSS and html. Designing is so much fun! My site includes articles and I thought it would be cool to include a comment box. Before coming here I have read many many posts about how to create this.

I am leaning towards using php and setting up a mysql database with my godaddy account. Through the forums I have read, it looks like I have to create two php pages one for adding comments and one for processing comments.

Do I use an html page with reference to the php page (comment box form is in html)?? In other words which page will be used to display the whole page.

How do you control where the comments end up displaying.
ex. above the comment box or below the comment box.

zeplin
Newbie Poster
4 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

If you have any <?php ?> tags in your script, you have to save it with the extension .php . If you want to save it with .html extension, then you need to modify your htaccess file. You can make use of only 1 page/script to do everything.
-- list the comments here --
...
....
Have the fields for name, comments etc, with a submit button. When the form is submitted, get the values and insert it to the table ! A small example.

<?php
if(isset($_POST['submit'])){
  $comment=$_POST['comment'];
  $q="insert into comments_table (comment) values ('$comment')";
mysql_query($q);
} 
$q="select comments from comments_table";
 $result=mysql_query($q);
while($row=mysql_fetch_array($result)){
 //list the comments
 echo $row['comments']."";
}
?>
<html>
<body>
<form method="Post" action="comments.php">
<textarea name="comments" rows=30 cols=10></textarea>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

This is just an example. And comments should be above the 'comment box'..

Cheers,
Naveen

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

Thanks this is helpful. I have not created article pages yet, so the php extension should be no problem. So, if I was creating a new article page and I wanted the guestbook to be on it, how would I add the php pages that I have created for the guestbook?

zeplin
Newbie Poster
4 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

guestbook to be on it ? How do you want to add it ?

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

theres only one problem in the comment box given by naveen
whenever you refresh it..
it resubmits the form...
is there any way to fix it?
please help..

clarence1723
Newbie Poster
1 post since Oct 2011
Reputation Points: 10
Solved Threads: 0
 
theres only one problem in the comment box given by naveen whenever you refresh it.. it resubmits the form... is there any way to fix it? please help..


Let me be the first to say welcome to daniweb and please do not bump 3 year old threads. Instead start a new thread and link to the old thread. As per the solution, perhaps you should set a cookie or session variable so that php knows if the user has posted the form and if the cookie is set then php knows that the form has already been sent so it doesn't need to process it again.

cwarn23
Occupation: Genius
Team Colleague
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
 
theres only one problem in the comment box given by naveen whenever you refresh it.. it resubmits the form... is there any way to fix it? please help..


I hope the second one is me ;)
BTW Add page redirection after comment is successfully sent!

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 
Ciircuit1111
Newbie Poster
1 post since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

I am not a developer but have managed to get a website developed. Taken me a month! I would like to have a comments box which will have a box for the name and emailof the person commenting. I would also like to get this comments box connected to a comments/feedback page on my site so that the comments can be seen by visitors, Apart from that, I also want to be able to stop spam, and be able to edit comments. Can anyone help?

mastersdog
Newbie Poster
1 post since May 2012
Reputation Points: 0
Solved Threads: 0
 

Post: Markdown Syntax: Formatting Help
You