468,242 Members | 1,722 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,242 developers. It's quick & easy.

writing to a txt file from a form

Hi all,

i am having trouble trying to write a script to a txt file. I am
attempting to seperate each posted item with the deliminater '|', but
for some reason i am getting the following information written:

peri|jones||||Submit

Whereas the desired input should be as follows WITHOUT the submit
button been printed and on a NEW LINE:

pe***************************@mail.com

The script i have test over and over again is as follows:

<?php

$data = implode('|', $_POST);

if (get_magic_quotes_gpc()) {
$data = stripslashes($data);
}

$listf = fopen ("username/member.txt", "a+");
$data = chop($data);
fwrite($listf, "$data\n");
fclose($listf);

?>

So, fellow php users how can i adapt the code to allow me to write the
input as above?
And how can i cleanly write to a new line as well?

Cheers,

Peri...

Apr 9 '07 #1
1 2962
programming wrote:
Hi all,

i am having trouble trying to write a script to a txt file. I am
attempting to seperate each posted item with the deliminater '|', but
for some reason i am getting the following information written:

peri|jones||||Submit

Whereas the desired input should be as follows WITHOUT the submit
button been printed and on a NEW LINE:

pe***************************@mail.com

The script i have test over and over again is as follows:

<?php

$data = implode('|', $_POST);

if (get_magic_quotes_gpc()) {
$data = stripslashes($data);
}

$listf = fopen ("username/member.txt", "a+");
$data = chop($data);
fwrite($listf, "$data\n");
fclose($listf);

?>

So, fellow php users how can i adapt the code to allow me to write the
input as above?
And how can i cleanly write to a new line as well?

Cheers,

Peri...
The submit button will be in the$_POST array, if you assign it a name
then you could 'unset' it before you implode your array... eg.

HTML: <input type="submit" name="submit" value="submit" />
PHP: @unset($_POST["submit"]);

That would remove the sumit button before you write, obviously the
submit button name would always have to be the same in each form.

I'm not sure what you mean about the new line, this appears to work just
fine for me with just the \n

<?php
if ( $_SERVER["REQUEST_METHOD"]=="POST" ) {

unset($_POST["submit"]);
$data = implode('|', $_POST);

if (get_magic_quotes_gpc()) {
$data = stripslashes($data);
}

$listf = fopen ("member.txt", "a+");
$data = chop($data);
fwrite($listf, "$data\n");
fclose($listf);

}
?>
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post">
username<input type="text" name="username" value="" /><br />
password<input type="password" name="password" value="" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
Apr 9 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Marc | last post: by
10 posts views Thread by Neil Trigger | last post: by
6 posts views Thread by Sebastian Kemi | last post: by
3 posts views Thread by CsharpNewcommer | last post: by
16 posts views Thread by iwdu15 | last post: by
1 post views Thread by Glenn Coyle | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.