jamescover
06-28-2007, 02: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..!
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..!