Results 1 to 5 of 5

Thread: PHP Text Files...

  1. #1
    Join Date
    Dec 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation PHP Text Files...

    I am working with a form and submitting it through a php file.

    When the form is submitted the php sends an email to the submitted email address, and to the administrator's email address. It also writes the message to a text file.

    As of now, I have this set up so that it writes each submission to the same file....however, I would like to be able to have the php write the submission to a different file each time...based off of their inputted username for instance.

    Here is the code I have:

    Code:
    $date=date("D F d Y");
    $time=time();
    $username=$_POST['username'];
    $email=$_POST['email'];
    $job=$_POST['job'];
    $posts=$_POST['posts'];
    $why=$_POST['why'];
    $approved=$_POST['approved'];
    $ip=$_SERVER['REMOTE_ADDR'];
    $victor="**REMOVED**";
    $file="staffapp.txt";
    $jofnn="**REMOVED**";
    
    
    $inputString = "$time, $date\n\n$username has applied for a staff position.\n\nHere is the information sumitted:\n\nUSERNAME: $username\n\nEMAIL: $email\n\nAPPLYING FOR: $job\n\nNUMBER OF POSTS: $posts\n\nINFO: $why\n\n$approved\n\nIP ADDRESS:  $ip\n\n====================================\n\n";
    
    $fp = fopen( $file , "a" );
    
    fwrite( $fp, $inputString );
    
    fclose( $fp );
    
    $to="$victor";
    $message2="$username,\nThank you for submitting your application!\nThe Administrators of the board shall review your application and get back to you in due course.\n\nThe following is your submitted information:\nUSERNAME: $username\nEMAIL: $email\nAPPLYING FOR: $job\nNUMBER OF POSTS: $posts\nINFO: $why\n**\n$approved\n**\nThanks again,\n The Global Forums Team\n\n------------\nThis is an automated message, please don't reply!";
    
    $message="Global Forums Administrators,\nThe following is a pending staff application.\n---------------\n\nUSERNAME: $username\n\nEMAIL: $email\n\nAPPLYING FOR: $job\n\nNUMBER OF POSTS: $posts\n\nINFO: $why\n\n$approved\n\nIP ADDRESS:  $ip\n\nSubmission Logged: **URL REMOVED**\n===============================\nCopy of Submitted email:\n----\n$message2";
    
    mail($to,"GF Staff Application",$message,"From: $email");
    
    mail($email,"GF Staff Application Submission",$message2,"From: $to");
    
    header( "Location: **URL REMOVED**");
    Is there anyway to create a new text file for each submission and name it according to their username?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Sure.

    $file="staffapp.txt"; sets the file. Use something else.

    You could use a timestamp with time(), or $_POST['username'], etc.

    Then change the fopen line to:
    $fp = fopen( $file , 'w+' );
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Dec 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have tried this in multiple formats...with no success.

    Could you perhaps give me the exact format I would use to name it with a timestamp...I like that idea.

    $file=time()".txt" or something....I don't know how to get the ".txt" extension on the file.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    To merge two strings, you need to use a dot character.

    $file = time().'.txt';
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Dec 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    oh...duh I should have known that...

    Thank you soooo much for all of your help!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •