creating a comment script
Posted: Wed May 13, 2009 6:46 am
am working on a script to submit and display comments on a web page.
The way it is setup is that the user writes comments in two text inputs, and ithe script submits the output to a textfile.
I am having trouble though. So far, I can not submit the data so that it creates a new line for each submission. The code I am using is:
This will work, except for the \n.
The output created is a single line in info.txt.
So i try and work with this to display the content of output.txt
First I make it into a string, and then try to manipulate it using:
But this will only return the first entry, and nothing else.
My question is, how do I set this up to display each entry in a seperate table row, every time
someone submits something?
Is there a better way to format the text file?
Is using list() and split() my best options?
Thanks
The way it is setup is that the user writes comments in two text inputs, and ithe script submits the output to a textfile.
I am having trouble though. So far, I can not submit the data so that it creates a new line for each submission. The code I am using is:
Code: Select all
<?php
$name = $_POST['name'];
$comment = $_POST['comment'];
$output = $name."\t".$comment."\t"."\n";
$fp = fopen("d:\hshome\c239198\local54memberforum.com\info.txt", "ab");
fwrite($fp, $output);
?>
The output created is a single line in info.txt.
So i try and work with this to display the content of output.txt
First I make it into a string, and then try to manipulate it using:
Code: Select all
<?php
$commenttext=file_get_contents("d:\hshome\c239198\local54memberforum.com\info.txt");
list($name, $comment) = split("\t", $commenttext);
echo "<tr bgcolor=6699CC>".
"<td>Name: $name</td>\n"."</tr>".
"<tr bgcolor=0066CC>".
"<td>Comment: $comment</td>\n"."</tr>\n";
?>
My question is, how do I set this up to display each entry in a seperate table row, every time
someone submits something?
Is there a better way to format the text file?
Is using list() and split() my best options?
Thanks