|
Posted by Tyno Gendo on 04/09/07 11:31
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:
>
> peri|password|perry|jones|xyz@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>
Navigation:
[Reply to this message]
|