PDA

View Full Version : php form processing to a text file..



crj
January 22nd, 2002, 15:59
hi, does anyone know of a php form processing script that adds the data to the end of an already existing txt file?

basically you input data, then the php script adds it to the end of a txt file....

i dont know php but it doesn't sound that hard to do....


<?php

$file_name = "data.txt";

$file_pointer = fopen($file_name, "a");

$lock = flock($file_pointer, LOCK_EX);
// Use 2 if you use < PHP4.0.2

if ($lock) {

fseek($file_pointer, 0, SEEK_END);
// Use this if < PHP4.0RC1 : fseek($file_pointer, filsize($file_name));

fwrite($file_pointer, "what u wanna write");
flock($file_pointer, LOCK_UN);
// Use 3 < PHP4.0.2

}

fclose($file_pointer);

print "data written to file successfuly";

?>



how do i make it so that "what you wanna write" is the data from a text field?

megapuzik
January 22nd, 2002, 16:31
Originally posted by crj
hi, does anyone know of a php form processing script that adds the data to the end of an already existing txt file?

basically you input data, then the php script adds it to the end of a txt file....

i dont know php but it doesn't sound that hard to do....


<?php

$file_name = "data.txt";

$file_pointer = fopen($file_name, "a");

$lock = flock($file_pointer, LOCK_EX);
// Use 2 if you use < PHP4.0.2

if ($lock) {

fseek($file_pointer, 0, SEEK_END);
// Use this if < PHP4.0RC1 : fseek($file_pointer, filsize($file_name));

fwrite($file_pointer, "what u wanna write");
flock($file_pointer, LOCK_UN);
// Use 3 < PHP4.0.2

}

fclose($file_pointer);

print "data written to file successfuly";

?>



how do i make it so that "what you wanna write" is the data from a text field?

eh , what ????? what do you want to do ?

cheatpark
January 22nd, 2002, 16:41
I think he wants a form and then making it write to a file using the code he has provided or something like that I think.

megapuzik
January 22nd, 2002, 16:51
Oh ok....
just make some html text field, and the name of the text field, later, will be a var name.....
and in the html form tag, you should do something like this :

<form method="post" action="the_file_whit_the_php_code.php" name="ajdf">
and when you will send the data from the html page to the php file, every form element will be a var (html form element = php var)...

OK ????

crj
January 22nd, 2002, 19:55
how do i get the html form elements to become php variables?

and how do i make the php file get the form elements?

crj
January 22nd, 2002, 22:07
nevermind, i got it...