tom_mk
asked on
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\r ecord.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\r ecord.txt' , 'a' );
$write_out = $tmp_comment.",".$tmp_url_ address;
fwrite ($fd, "\n$write_out\n");
fclose( $fd );
?>
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><
// READ LINE
$fs = fopen( 'C:\Program Files\EasyPHP1-7\www\url\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\r
$write_out = $tmp_comment.",".$tmp_url_
fwrite ($fd, "\n$write_out\n");
fclose( $fd );
?>
ASKER
('location:' . $_SERVER['REQUEST_URI'); >> localtion is my websaddress?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.