what wrong with my file?

hi,

wat i trying to do here is .. reading content from a file and disply it.
and then get some input from the user and save it into file and display it.

this is the format of my record.txt

web1, www.web1.com // <--- one set of data
web2, www.web2.com 

my problem with my code is that...
i can't get my prog to write one set of data written line by line (one set of data per line)
but all my data will b written on one line even thought i have assigned "\n" to the back of my every set of data.

another prob
while using $_POST
whenever, i 'refresh' the screen, the data that has been post once (from submit-button), will b re-post again.
how can i prevent this from happening?


this is my code.

<?php

$my_array = localtime(time(), 1);
$month = $my_array["tm_mon"] + 1 ;
$day = $my_array["tm_mday"] ;
$year = $my_array["tm_year"] +1900 ;
$dayOfWeek = $my_array["tm_wday"] ;
$weekdays = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") ;


echo "<h3>Current Time : $month-$day-$year > $weekdays[$dayOfWeek]<br></h3>" ;




// READ LINE

$fs = fopen( 'C:\Program Files\EasyPHP1-7\www\url\record.txt', 'r' );
//$fd = fopen( 'filedestination', 'w' );

while( ! feof( $fs ) )
{
      $tmp = fgets( $fs );

      # replace this line with whatever you want to do to each line
      //$tmp = process_line( $tmp );
      
      $process = explode(",", $tmp);
      echo "<a href = \"$process[1]\"> $process[0]</a> <br>";

      //fputs( $fd, $tmp );
}

//fclose( $fd );
fclose( $fs );

echo "<br>";



echo "<FORM ACTION=\"url.php\" METHOD=POST>";

echo " Comment <br>";
echo "<input type=text name = \"comment\" size=\"25\" ><br>";
echo " Address <br>";
echo "<input type=text name = \"url_address\" size=\"25\" ><br>";
echo "<INPUT TYPE=submit NAME=submit_button VALUE=\"Submit\">";
echo "</FORM>";

echo " -----------------<br>";

$tmp_comment = "";
$tmp_url_address = "";
$tmp_comment = $_POST["comment"];
$tmp_url_address = $_POST["url_address"];

$fd = fopen( 'C:\Program Files\EasyPHP1-7\www\url\record.txt', 'a' );

$write_out = $tmp_comment.",".$tmp_url_address;

fwrite ($fd, "\n$write_out\n");

fclose( $fd );

?>
tom_mkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

virmaiorCommented:
in answser to the reposting question (part 2),
you need to have the screen that you redisplay not be the instant result of the posted data (that's why hitting refresh makes the data get re-entered).  There are a few ways to do this.  Probably the most prevelant is
a header redirect
('location:' . $_SERVER['REQUEST_URI');

in answer to part 1, try using the function nl2br($text)
when you are displaying it for the user.... (assuming this is a web thing).  "\n" don't mean jack for HTML display.
0
tom_mkAuthor Commented:
('location:' . $_SERVER['REQUEST_URI');  >> localtion is my websaddress?
0
virmaiorCommented:
header('location:' . $_SERVER['REQUEST_URI]');

it's an internal PHP variable that reflects what page was asked for
if you just redirect to the same page, then they can't refresh (since there is no longer any POST data).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.