...

View Full Version : writing to a text file and printing results onscreen



jamescover
06-28-2007, 03:10 AM
Hi,,,


I tried for about an hour to come up with a simple script to write info derived from a web form to a text file, then print the results onscreen with no luck.


Unfortunately, I accidentally deleted my script, haha. But a search of the forums turned up something similar, except I used fputs() and then locked the file for writing then unlocked it.



<?php

$file = $_POST['guest'];
$handle = fopen("test.txt", "w");
fwrite($handle, $file);
fclose($handle);
print $file;

?>




I used print $file to see if it was grabbing the variable value from the form and it was, but I can't get it to write it to the file....

EDIT:


I found a similar script to my original:




<?php

$fp = fopen('test.txt', 'w');
$string = $_POST['guest'];

flock($fp, LOCK_EX);
fputs($fp, $string);
flock($fp, LOCK_UN);
fclose($fp);

?>



Again, if i use print by itself, it works, but it won't write to the file.




<?php

$strng = $_POST['guest'];
print $strng;

?>


Also if I do the following, it will write to the file, but not print:



<?php

$file = "Some Text";
$handle = fopen("test.txt", "w");
fwrite($handle, $file);
fclose($handle);
print $file;

?>







any help will be appreciated..!

_Aerospace_Eng_
06-28-2007, 09:08 AM
Use echo instead of print.

jamescover
06-28-2007, 02:14 PM
Use echo instead of print.




Yeah, thanks...

Well, it's sometimes the little things...

This is what my form action tag looked like:

action=""http://motox.ekigroup.com/guesttest/guestbook/processXML.php"


Works perfectly now...

_Aerospace_Eng_
06-28-2007, 06:50 PM
lol. Probably would have caught that if you had posted your form code.

jamescover
06-28-2007, 07:27 PM
lol. Probably would have caught that if you had posted your form code.

Well, I appreciate the effort...

Doesn't take much to spoil the soup...


-james



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum