|
-
Oct 8th, 2007, 11:34 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] PHP Comment Box
Alright, I really need help with this, I have no idea about php, I used to be ok with it, but now I cant really remember anything. I need to make a commentbox on one of my sites, but all I want it to do is submit it to a text file in this format:
Code:
Name:
Comment:
----------------
I don't remember how to do this, but this shouldn't require me to setup a database because it is being added to a text file, right?
Thanks in advance.
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Oct 9th, 2007, 08:00 AM
#2
-
Oct 9th, 2007, 03:32 PM
#3
Thread Starter
Hyperactive Member
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Oct 9th, 2007, 09:46 PM
#4
Re: PHP Comment Box
he answered the question that you asked. Do you have any other questions?
My usual boring signature: Something
-
Oct 10th, 2007, 02:35 PM
#5
Thread Starter
Hyperactive Member
Re: PHP Comment Box
no, but how would I do that, that was my question...
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Oct 10th, 2007, 04:22 PM
#6
Re: PHP Comment Box
 Originally Posted by Bobalandi
but this shouldn't require me to setup a database because it is being added to a text file, right?
That is the only sentence with a question mark at the end, so it is the only question you asked. 
A more appropriate question would be "How would i do this".
well you need a form...
HTML Code:
<form action="YOUR PAGE.php" method="POST">
<input type="text" name="name">
<textarea name="comment"></textarea>
<input type="submit" name="submit">
and your code...
PHP Code:
if (isset($_POST['name'])&&isset($_POST['comment'])) {
$myFile = "comments.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Name: " . $_POST['name'] . "\n";
fwrite($fh, $stringData);
$stringData = "Comment: " . $_POST['comment'] . "\n";
fwrite($fh, $stringData);
$stringData = "-----------------------------------\n\n\n";
fwrite($fh, $stringData);
fclose($fh);
}
php.net is a great tool
My usual boring signature: Something
-
Oct 10th, 2007, 08:11 PM
#7
Thread Starter
Hyperactive Member
Re: PHP Comment Box
php.net? but thanks for the code...
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Oct 10th, 2007, 08:31 PM
#8
Thread Starter
Hyperactive Member
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Oct 10th, 2007, 10:43 PM
#9
Re: PHP Comment Box
 Originally Posted by Bobalandi
hmmm... It didnt work...
That's about as helpful as mixing marmalade with Toilet Duck.
What happens to make it appear to not work?
-
Oct 10th, 2007, 11:18 PM
#10
Re: PHP Comment Box
 Originally Posted by Bobalandi
php.net? but thanks for the code...
php.net is the PHP home page... all the built in functions of php, with examples. google is also a great tool.
Google: "php append to file", get the results you want
My usual boring signature: Something
-
Oct 11th, 2007, 02:40 PM
#11
Thread Starter
Hyperactive Member
Re: PHP Comment Box
oo, the website, I thought you meant an app, thanks. And as for it not working, it just doesnt accomplish anything, all it does is forward you to the php page, not add the text or anything.
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Oct 11th, 2007, 04:10 PM
#12
Re: PHP Comment Box
post all the code you have on the page
My usual boring signature: Something
-
Oct 11th, 2007, 04:30 PM
#13
Thread Starter
Hyperactive Member
Re: PHP Comment Box
ok, I have 3 pages one is an empty text page called comments.txt
next it the html form on one page.
Code:
<form action="comment.php" method="POST" id="Comment">
<label>Name:</label><br />
<input type="text" name="name"><br />
<label>Comment:</label><br />
<textarea name="comment"></textarea><br />
<input type="submit" name="submit">
</form>
last ly there is the php page, comment.php
Code:
if (isset($_POST['name'])&&isset($_POST['comment'])) {
$myFile = "comments.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Name: " . $_POST['name'] . "\n";
fwrite($fh, $stringData);
$stringData = "Comment: " . $_POST['comment'] . "\n";
fwrite($fh, $stringData);
$stringData = "-----------------------------------\n\n\n";
fwrite($fh, $stringData);
fclose($fh);
}
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Oct 11th, 2007, 05:50 PM
#14
Re: PHP Comment Box
do you have php tags? <?php & ?>
My usual boring signature: Something
-
Oct 11th, 2007, 07:22 PM
#15
Thread Starter
Hyperactive Member
Re: PHP Comment Box
umm... should I? that is everything that is on the page? and also, how can I maek it redirect somewhere?
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Oct 11th, 2007, 07:51 PM
#16
Re: PHP Comment Box
haha. yes, php tags are required. it will be just outputted as html if you dont.
redirect: header("Location: mypage.php");
My usual boring signature: Something
-
Oct 11th, 2007, 08:32 PM
#17
Thread Starter
Hyperactive Member
Re: PHP Comment Box
ok, thanks I appreciate everything, resolved, I think.
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Oct 11th, 2007, 10:13 PM
#18
Re: [RESOLVED] PHP Comment Box
no problems! dont forget to give rep accordingly.
My usual boring signature: Something
-
Oct 14th, 2007, 10:18 AM
#19
Thread Starter
Hyperactive Member
Re: [RESOLVED] PHP Comment Box
It still isn't working for some reason, but that is ok, I decided to work with asp.net instead.
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Oct 14th, 2007, 12:46 PM
#20
Re: [RESOLVED] PHP Comment Box
gasp! how could you move to asp.net! nooo!!!
lol
ok, well as long as you find a programming language that you can work with, then that is always the best.
Thanks for the rep
My usual boring signature: Something
-
Oct 15th, 2007, 07:36 PM
#21
Thread Starter
Hyperactive Member
Re: [RESOLVED] PHP Comment Box
you deserved it (the rep lol), and I found asp.net to better cater to my needs, and I have a bunch of people, who I know who can help me with, and then there is timeshifter... lol
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
-
Oct 15th, 2007, 07:40 PM
#22
Re: [RESOLVED] PHP Comment Box
lol. well i wish you the best on your ASP.NET journey
My usual boring signature: Something
-
Oct 16th, 2007, 02:45 PM
#23
Thread Starter
Hyperactive Member
Re: [RESOLVED] PHP Comment Box
Haikus are easy.
But sometimes they don't make sense.
Refrigerator.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|