Current location: Hot Scripts Forums » Programming Languages » PHP » Help with writing to a html file


Help with writing to a html file

Reply
  #1 (permalink)  
Old 07-20-06, 03:55 AM
rameez rameez is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Help with writing to a html file

Hi,
I have written a script view.php which takes input from a html form (another file) and then displays it after formatting a processing it. Now I want to save that formatted form exactly as it appears on the browser to a html file in such a way that each time a user fills the form it saves it to a unique html file with users name as the file name.
Can someone please guide me to the easiest way of writing the output of view.php to a html file each time it is used. I know basic file handling but don't know where to start for this particular case

Thanks,
Rameez.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-20-06, 06:32 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Could you may post the code you've got so far?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-21-06, 12:26 AM
rameez rameez is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Code:
<html>
<head>

  <link rel="stylesheet" href="intern.css">
  <title>Internship Completion Report</title>


</head>

<body>

<?php

print "<h3>Name</h3>";
print $_POST['intern_name'];

print "<h3>Contact Number</h3>";
print $_POST['number'];

print "<h3>Sex</h3>";
print $_POST['sex'];

print "<h3>Institution currently attending</h3>";
print $_POST['institution_name'];

print "<h3>Class/Year</h3>";
print $_POST['class'];

print "<h3>Internship Module</h3>";
print $_POST['module'];

print "<h3>Areas of interest</h3>";
for ( $counter = 0; $counter <= 14; $counter += 1 ){
	if ( $_POST["interests"][$counter] != "" ) {
	print $_POST["interests"][$counter];
	print "<br>";
	} else {
	}
}

print "<h3>What Expectations did you have from this internship when you joined?</h3>";
for ( $counter = 0; $counter <= 7; $counter += 1 ){
	if ( $_POST["expectations"][$counter] != "" ) {
	print $_POST["expectations"][$counter];
	print "<br>";
	} else {
	}
}

print "<h3>Which of the following objectives did you achieve?</h3>";
for ( $counter = 0; $counter <= 3; $counter += 1 ){
	if ( $_POST["achievements"][$counter] != "" ) {
	print $_POST["achievements"][$counter];
	print "<br>";
	} else {
	}
}

print "<h3>Which skills did you develop during the internship</h3>";
for ( $counter = 0; $counter <= 5; $counter += 1 ){
	if ( $_POST["skills"][$counter] != "" ) {
	print $_POST["skills"][$counter];
	print "<br>";
	} else {
	}
}

print "<h3>Which of the Community Service Projects did you enjoy?</h3>";
for ( $counter = 0; $counter <= 2; $counter += 1 ){
	if ( $_POST["enjoyed"][$counter] != "" ) {
	print $_POST["enjoyed"][$counter];
	print "<br>";
	} else {
	}
}

print "<h3>Did the internship give you an insight of the hardships faced by the underprivileged?</h3>";
print $_POST['got_insight'];

print "<h3>Do you often feel the urge to help the underprivileged?</h3>";
print $_POST['helping_urge'];

print "<h3>What things do you have in mind to help the underprivileged once you have completed this internship?</h3>";
print $_POST['things_in_mind'];

print "<h3>Did you feel happy raising funds for the underprivileged?</h3>";
print $_POST['happy_feel'];

print "<h3>If you were to join a medical college, would you be happy to join Fatima Memorial Medical College</h3>";
print $_POST['join_college'];

if ( $_POST['join_college'] == "Yes" || $_POST['join_college'] == "No") {
	print "<h3>Why</h3>";
	print $_POST['why_fms'];
	print "<br>";
	} else {
	}

print "<h3>Which areas of the following internship programme you did not enjoy working in</h3>";
for ( $counter = 0; $counter <= 9; $counter += 1 ){
	if ( $_POST["not_enjoy"][$counter] != "" ) {
	print $_POST["not_enjoy"][$counter];
	print "<br>";
	} else {
	}
}

print "<h3>According to your perception, overall the internship programme was</h3>";
print $_POST['perception'];

print "<h3>Yearly at the end of Internship programme, we arrange a function. Would you like to participate? Please specify your talent</h3>";
print $_POST['talent'];

print "<h3>You had a rotation according to the work plan handed over to you. Which department did you like working in, and why?</h3>";
print $_POST['fav_dept'];

print "<h3>You had a rotation according to the work plan handed over to you. Which department you DID NOT like working in, and why?</h3>";
print $_POST['dislike_dept'];

print "<h3>Were you happy with your supervisors in the departments?</h3>";
print $_POST['supervisor'];

if ( $_POST['supervisor'] == "No" ) {
	print "<h3>If No, then please explain</h3>";
	print $_POST['supervisor_view'];
	print "<br>";
	} else {
	}

print "<h3>Please Comment on how we at Fatima Memorial can make this Internship Programme better. Your comments will be highly appreciated</h3>";
print $_POST['comment'];

?>

</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-21-06, 12:43 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
For the basic way of capturing this to save it in a file, use output buffering -
PHP Code:

<?php

ob_start
();

// output your existing html/ php echo output here

$capture ob_get_contents(); // get the output buffer into a variable
ob_end_clean(); // empty the buffer

// complete your code to write the contents of the $capture variable to a file with the proper file name...
?>
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-21-06, 01:35 AM
rameez rameez is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks, another question is that I want people to view the results before it saves it to a file so the above files actually just shows them what they entered. If I use a submit button at the end of the above file which point to another file e.g save.php all the variables show up empty.
How can I use the above function in my script should I just just add it in the start for the above mentioned code if yes how do I call this function on the same file after viewing it such a way that variable are not emptied.

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 07-21-06, 01:53 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
You can echo the $capture variable to cause the page to be displayed. You can add the code for a submit form after the echo. If they click on the submit button, that code/page would do the logic to save the contents of the $capture variable to the file. To pass the $capture variable to the "save" page, either save it into a session variable or pass it as a hidden variable in the submit form.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML code file update on the webserver using CGI script sujata_ghosh Perl 31 07-06-06 04:06 AM
Referencing HTML code from a second file msoucy HTML/XHTML/XML 2 07-18-05 01:25 AM
script to write to/update an html file tjvfox Script Requests 2 06-13-05 11:41 AM
How to make a list of links from HTML file? hordubal PHP 3 04-17-05 12:05 PM
Saving php generated file as html file GS300 PHP 0 12-29-04 04:34 AM


All times are GMT -5. The time now is 10:23 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.