473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 3118
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marc | last post by:
Hello, I have a question about how PHP handles multiple file reads/ writes. I made a page containing a self-submitting form where the user can type his name, topic and a text. When he submits the...
5
by: Paul C-T | last post by:
Hi, Am I trying to be too clever here? I am trying to write a PHP page to enable me to enter values into a form then write those values to a text file. I want to use the form & table that...
10
by: Neil Trigger | last post by:
Is there a way of creating a seperate text file on a server every time a form is sent? -- ¿ Trigger ? http://www.magic2k.com/ http://www.oddmap.co.uk
6
by: Sebastian Kemi | last post by:
How should a write a class to a file? Would this example work: object *myobject = 0; tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object)); / sebek
3
by: CsharpNewcommer | last post by:
Hi Can someone tell me how to write the data from a TextBox (txt) or Label (lbl) to a text file to be printed. I have read the info from msdn.microsoft.com/library on "Writing Text to a File",...
16
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
1
by: Glenn Coyle | last post by:
Hi I am having trouble writing the file path of a image to the database,also for some reason it is not uploading the images, anyone have any ideas? the code is below: if($_POST ==...
0
grassh0pp3r
by: grassh0pp3r | last post by:
Hello, I'm trying to make a very simple comments page on my site using PHP and am having problems somewhere. I am very new to PHP. I was able to create one that works with comments appended, but...
3
pradeepjain
by: pradeepjain | last post by:
<html> <head> </head> <body> <?php $filehandle = fopen("welcome.txt","r"); if(filesize("welcome.txt")=='0') {
0
by: mcc99 | last post by:
Amazing, I surfed around to find a simple utility that could list files recursively from a given top folder down through it, writing out the path and filename in simple \path\file_name form, without...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.