Jump to content

Simple form that appends to a text file


Alice

Recommended Posts

Hi, This is probably something very simple for most of you, but I'm very new to php coding, so thanks in advance for your help!

 

All I'm needing to do is have a one field form on my site that will append the data to a text file.  I have it working, however it enters data into the file immediately after the previous data without a comma or a line break.  This will make it very hard to export later on.

 

Here is the code I'm using

 

$fh = fopen("email.txt", "a");
fwrite($fh, $email);
fclose($fh);

 

What can I do here to have it enter a comma or a line break?

Link to comment
Share on other sites

I think I figured it out.  Here is what I added.  If someone could let me know this is correct of if there is a better way?  It seems to be working for now.

 

 

$fh = fopen("formdata.txt", "a");
 
fwrite($fh, "$email\r\n");
fclose($fh);
 
Thanks!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.