Comments box/guestbook php

This is a discussion on "Comments box/guestbook php" within the PHP Forum section. This forum, and the thread "Comments box/guestbook php are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jun 9th, 2008, 22:42
Junior Member
Join Date: Jun 2008
Location: Ireland
Posts: 11
Thanks: 5
Thanked 0 Times in 0 Posts
Comments box/guestbook php

I had a good look around to see if this was answered already and couldn't find anything that I understood!

I want visitors to enter a comment in a page called Comment.htm:

HTML: Select all
<html><head>
 
 <title>Guestbook</title><link rel="stylesheet" type="text/css" href="style.css"></head>
<body> 
<hr />
<center><form action="comments.php" method="get">
 <textarea rows="8" cols="40"></textarea><br />
  <input type="image" name="submit" src="Buttons/Submit_off.png" onmouseover="this.src='Buttons/Submit_on.png';"onmouseout="this.src='Buttons/Submit_off.png';"> 
</form></center>
<hr />
</body>
</html>
There's a lot of rubbish about mouseovers that you can ignore. As you see I used a php file called comments.php. I want this to save the comments and post them onto a page called View.htm. But I don't have a clue how to do it as you may have guessed!

So what do I put in comments.php?
And is Comment.htm even right? I'm not sure of this bit: form action="comments.php"

Thanks for any help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jun 10th, 2008, 08:50
Junior Member
Join Date: May 2008
Location: Colorado
Age: 19
Posts: 27
Thanks: 0
Thanked 1 Time in 1 Post
Re: Comments box/guestbook php

form action="comments.php" is where the user will head to after having clicked on the submit button. one thing you might want to change though is the method of retrieving the data processed, you are using the get method and for a comment you should probably(in my opinion) use the post method(just change get to post). then in comments.php put the comment value into a variable, insert it into a database or flat file and if there were no errors tell the user they have successfully created the comment and re-direct em or tell them their error, and in view.php open the flat file, get the data and post it to the screen or just simply retrieve the row data from your database and post it to the screen.

making any sense? It's kinda hard to explain less thoroughly :\ for me at least....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jun 10th, 2008, 09:23
Jack Franklin's Avatar
Moderator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,408
Blog Entries: 8
Thanks: 18
Thanked 14 Times in 14 Posts
Re: Comments box/guestbook php

Quote:
I want this to save the comments and post them onto a page called View.htm. But I don't have a clue how to do it as you may have guessed!
It's not as easy as it might seem, Basically if you want to do this the best way is to, as luv2php says, to store the comments in a database. The heading in the database might be 'Name', 'Email', 'Date', 'Comment' for example. Then using PHP, you store the data in that form into the database, and then fetch the data in view.php using PHP.

Have a look on W3Schools for PHP/MySQL beginners tutorials. It's really easy once you get the hang of it
__________________
Jack Franklin - Webforumz Moderator
(x)HTML | CSS | PHP | MySQL | JQuery (Javascript)
Contact: My Blog | Twitter | Delicious
Want Lessons? PM me.
If you think I've helped, please press the 'Thanks' Button.
Last Blog Entry: A Week with VBulletin (Aug 28th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jun 10th, 2008, 12:30
Junior Member
Join Date: Jun 2008
Location: Ireland
Posts: 11
Thanks: 5
Thanked 0 Times in 0 Posts
Re: Comments box/guestbook php

Quote:
Originally Posted by luv2php View Post

making any sense? It's kinda hard to explain less thoroughly :\ for me at least....
Yeah I get what you're saying, I just have to convert your words into php and I think I'll be able to do it.

Quote:
Originally Posted by Jack Franklin View Post
Have a look on W3Schools for PHP/MySQL beginners tutorials. It's really easy once you get the hang of it
That's exactly what I'll do this instant. Thanks for the help both of you!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jun 10th, 2008, 13:28
Junior Member
Join Date: Jun 2008
Location: Ireland
Posts: 11
Thanks: 5
Thanked 0 Times in 0 Posts
Re: Comments box/guestbook php

Ok now I have a follow up question...

This is what I've got so far (mainly guess work/ripped off tutorials seeing as I know nothing about php!):

PHP: Select all

<?php
$comments_made 
= ("comments.txt");
$comments file($comments_made);
$fp fopen($comments_made "a+");
fputs($fp $new_comment);
fclose($fp);
echo 
$comments_made;
?>
(I realise that the contents of comments.txt will be repeatedly written to whatever page it's going to instead of updated as new comments are added, which probably isn't the best way of doing things).

How do I assign a variable that I have called $new_comment to the actual new comment? In other words the visitor enters whatever comment e.g. "Hello". Then I want $new_comment = "Hello", but how do I do that?

Thanks again
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jun 10th, 2008, 18:53
Jack Franklin's Avatar
Moderator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,408
Blog Entries: 8
Thanks: 18
Thanked 14 Times in 14 Posts
Re: Comments box/guestbook php

Assuming the new comment goes in the 1st line, you could create an array of every line in the text file and find the first line. Not sure how it's done, but I can find out for you if I am on the right lines?
__________________
Jack Franklin - Webforumz Moderator
(x)HTML | CSS | PHP | MySQL | JQuery (Javascript)
Contact: My Blog | Twitter | Delicious
Want Lessons? PM me.
If you think I've helped, please press the 'Thanks' Button.
Last Blog Entry: A Week with VBulletin (Aug 28th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Jun 16th, 2008, 10:53
Junior Member
Join Date: Jun 2008
Location: Ireland
Posts: 11
Thanks: 5
Thanked 0 Times in 0 Posts
Re: Comments box/guestbook php

Quote:
Originally Posted by Jack Franklin View Post
Assuming the new comment goes in the 1st line, you could create an array of every line in the text file and find the first line. Not sure how it's done, but I can find out for you if I am on the right lines?
Hey sorry for the late reply Jack, I wasn't at home for the past few days, didn't have access to a computer etc. Anyway, it's ok, you don't have to find out if you're not sure! I'll have a poke around the internet myself for it. Thanks for the help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Jun 16th, 2008, 22:50
Jack Franklin's Avatar
Moderator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,408
Blog Entries: 8
Thanks: 18
Thanked 14 Times in 14 Posts
Re: Comments box/guestbook php

Hey Idiot! :P

I have not tried this script but I've just flicked through my PHP Anthology:

PHP: Select all

$file file(comments.txt);
$lines count($file); //counts number of lines, creates array of  lines
$new_comment $lines[0]; //first line is first array line, which is [0] 
Let me know what happens.
__________________
Jack Franklin - Webforumz Moderator
(x)HTML | CSS | PHP | MySQL | JQuery (Javascript)
Contact: My Blog | Twitter | Delicious
Want Lessons? PM me.
If you think I've helped, please press the 'Thanks' Button.
Last Blog Entry: A Week with VBulletin (Aug 28th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Sep 26th, 2008, 11:24
Junior Member
Join Date: Jun 2008
Location: Ireland
Posts: 11
Thanks: 5
Thanked 0 Times in 0 Posts
Re: Comments box/guestbook php

Quote:
Originally Posted by Jack Franklin View Post
Let me know what happens.
Sorry I never saw this...I haven't been online since June. I'd given up on this for a while but I tried your code there and it seems to work out fine. Only time will tell if it actually works when people submit some comments (haven't the page up yet).

Thanks for the help. Better late than never!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Sep 26th, 2008, 14:11
Jack Franklin's Avatar
Moderator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,408
Blog Entries: 8
Thanks: 18
Thanked 14 Times in 14 Posts
Re: Comments box/guestbook php

Ok kool, any probs post back.
__________________
Jack Franklin - Webforumz Moderator
(x)HTML | CSS | PHP | MySQL | JQuery (Javascript)
Contact: My Blog | Twitter | Delicious
Want Lessons? PM me.
If you think I've helped, please press the 'Thanks' Button.
Last Blog Entry: A Week with VBulletin (Aug 28th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
New to php and need some help with a guestbook daveclissold PHP Forum 4 Mar 25th, 2007 18:15
guestbook-feedback? linn Starting Out 6 Jan 8th, 2007 16:19
guestbook tell-tale heart Web Page Design 2 Jun 19th, 2005 00:40


All times are GMT. The time now is 02:34.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42