Writing to a file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rayner75
Forum Newbie
Posts: 11
Joined: Sun Feb 20, 2005 4:45 pm

Writing to a file

Post by rayner75 »

Hello, on my site i have a feedback page feedback.htm
and the forms action points to reply.php where i write out what the person has put.
I can also get it to write to a text file, but it goes along in a line,
i am not sure how to get it to write to a text file line by line
Example:
Name: Andy
Age: -20
at the Momement i am getting

Name: Andy Age: - 20 ect....

Here is the code in my reply.php

Code: Select all

<?php
		$name = $_POST&#1111;'name'];
		$age = $_POST&#1111;'age'];
		$member = $_POST&#1111;'member'];
		$reserve = $_POST&#1111;'reserve'];
		$useful = $_POST&#1111;'useful'];
		$information = $_POST&#1111;'information'];
		$comments = $_POST&#1111;'comments'];
		
		echo &quote;<b>Name: </b>&quote;.$name; ?><br><?
		echo &quote;<b>Age: </b>&quote;.$age; ?><br><?
		echo &quote;<b>Current Member? </b>&quote;.$member; ?><br><?
		echo &quote;<b>Have you ever reserved anything? </b>&quote;.$reserve; ?><br><?
		echo &quote;<b>Do you find this site useful? </b>&quote;.$useful; ?><br><?
		echo &quote;<b>Do you think the information is up-to-date? </b>&quote;.$information; ?><br><?
		echo &quote;<b>Any Comments? </b>&quote;.$comments; 
		
		$SEPARATOR = &quote;::&quote;;
      
      	$filename = 'feedback.txt';
		
      
      	$details = &quote;Name: $name&quote;.$SEPARATOR.
       	           &quote;Age: $age&quote;.$SEPARATOR.
		   		   &quote;Current Member? $member&quote;.$SEPARATOR.
				   &quote;Reserved Anything? $reserve&quote;.$SEPARATOR.
				   &quote;Site Useful? $useful&quote;.$SEPARATOR.
				   &quote;Up-to-date Infor? $information&quote;.$SEPARATOR.
				   &quote;Comments? $comments&quote;.$SEPARATOR;
                         
      
       $file = fopen($filename,&quote;a&quote;);
       fputs ($file, $details);
       fclose($file);
?>
Thanks for any help
Andy
User avatar
oceglok
Forum Newbie
Posts: 5
Joined: Sun Mar 27, 2005 2:03 pm
Location: Nagoya-City, Japan

Post by oceglok »

Maybe

Code: Select all

$SEPARATOR = "::\r\n";
Hope, this helps
oceglok
rayner75
Forum Newbie
Posts: 11
Joined: Sun Feb 20, 2005 4:45 pm

Post by rayner75 »

Thanks that helped :)
Post Reply