Current location: Hot Scripts Forums » Programming Languages » PHP » Append to a Text File

Append to a Text File

Reply
  #1 (permalink)  
Old 07-22-03, 06:15 PM
Industriality Industriality is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Question Append to a Text File

This should be very simple; here's my situation:

I have a list of names contained in a TXT file (names.txt). It's basically a sign-up list. There is one name per line. This is not an HTML file, so the line endings should not be <br> (I assume). So here is an example of what names.txt looks like:
Code:
Brian
Sarah
Steve
Jennifer
John
Amy
Dave
Now on my website I have a form that will be processed by append.php (this is the script I need your help to create). The form contains one text field named "First_Name" and a submit button. The form is named "My_Form" if that matters. Now, when someone types in their name and clicks Submit, append.php should take that name and append it to "names.txt".

Simple, right? So what code does append.php need to have to process the form in this way? I think the functionality of this is similar to a blog, in it's very simplest form.

Also, it needs to be functional with global variables turned off, if that matters. And the form can be processed via POST or GET, it doesn't matter to me.

Any help is appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-22-03, 08:18 PM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Location: Michigan
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
well if u want the names.txt to bre used u need to use the fopen() function this isnt that hard to do
__________________
Elite Bulletin Board
http://elite-board.us
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-23-03, 02:38 AM
ChristGuy ChristGuy is offline
Operations Support Develo
 
Join Date: Jun 2003
Location: Rivonia, South Africa
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Greetingz...

PHP Code:
<?php
  
if (ISSet($_REQUEST["First_Name"]))
  {
    
$FirstName $_REQUEST["First_Name"];
  }
  else
  {
    Die( 
"Please enter a value in the name field..." );
  }

  
$Handle FOpen("names.txt""a+") or
    Die( 
"Error opening file" );

  if (!
FWrite($Handle$FirstName "\n"))
  {
    Die( 
"Error writing to file!" );
  }

  
FClose($Handle) or
    Die( 
"Error closing file!" );

  print( 
"Name: " $FirstName " Saved to file..." );
?>
that should work...
__________________
Till We Meet Again...
Clifford W. Hansen
Aspivia (Pty) Ltd

"We Have Seen Strange Things Today!" Luke 5:26
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-23-03, 10:44 AM
Industriality Industriality is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
That works very well, thank you very much. I appreciate it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code to edit a text file mdhall Script Requests 4 11-18-08 06:23 AM
Writes to a text file gamextremer2003 JavaScript 4 09-11-03 09:43 AM
text file to link rush989 Script Requests 3 08-29-03 06:12 PM
Need to submit form to database and text file - Any ideas how? dpreiss ASP 1 08-21-03 06:02 PM
Upload file type and size limiter! Arctic ASP 1 08-02-03 07:06 PM


All times are GMT -5. The time now is 08:56 PM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.