+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 22
Web Development Thread, PHP to text file in Coding and Web Development; I'm just fiddling with a bit php that adds some data from a form to a mysql database. At the ...
  1. #1

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    493
    Thanked 688 Times in 443 Posts
    Rep Power
    237

    PHP to text file

    I'm just fiddling with a bit php that adds some data from a form to a mysql database. At the same time this form is submitted I want to add the same data to a text file.

    Can anybody help me with how to achieve this?

  2. IDG Tech News

  3. #2

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Bristol
    Posts
    12,970
    Blog Entries
    24
    Thank Post
    438
    Thanked 1,502 Times in 1,179 Posts
    Rep Power
    459
    This should tell you how to do it: PHP Tutorial - File Write

  4. Thanks to localzuk from:

    Hightower (23rd October 2008)

  5. #3

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    493
    Thanked 688 Times in 443 Posts
    Rep Power
    237
    Cheers localzuk.

    The file goes back to itself when submitted so the user can submit something different straight away. As confirmation of submitting the previous one successfully I was wanting to put something like:

    You have successfully added $string

    How would I go about doing this?

  6. #4

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    493
    Thanked 688 Times in 443 Posts
    Rep Power
    237
    Any ideas?

  7. #5
    budgester's Avatar
    Join Date
    Jan 2006
    Location
    Enfield, Middlesex
    Posts
    446
    Thank Post
    3
    Thanked 30 Times in 27 Posts
    Rep Power
    18
    Can you post some code to show how far you have got, then we can help you.

  8. #6

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    493
    Thanked 688 Times in 443 Posts
    Rep Power
    237
    I have a form on a page with a field called 'txtTitle'. When this form is submitted it adds that info to a database and then goes back to the same page so they can add something again. All I want is to show what they have just added so they know they have been successful.

    Something like print $txtTitle

    I don't want to post code because I'm a little ashamed of it. Any help is appreciated

  9. #7
    tmcd35's Avatar
    Join Date
    Jul 2005
    Location
    Norfolk
    Posts
    3,056
    Blog Entries
    9
    Thank Post
    441
    Thanked 410 Times in 356 Posts
    Rep Power
    103
    I wouldn't be ashamed of your code - you should see the horror that is some of mine! I think there a generally two ways of doing what you want, if I understand it correctly.

    The first is to use a cookie or session to pass a couple of variables - a flag and the submitted text. You could then reload the page, check the flag and

    if flag = 1 then
    flag = 0
    print $string
    end if

    Or, the other way is to do it with out reloading the page. This would require some Javascript. Javascript can pick up an onClick() event on the submit button and can be used to print the success command to the screen.

    I'd probably use the first method myself along with a test to make sure they were successful.

  10. Thanks to tmcd35 from:

    Hightower (23rd October 2008)

  11. #8
    My220x's Avatar
    Join Date
    Feb 2008
    Location
    UK
    Posts
    257
    Blog Entries
    8
    Thank Post
    9
    Thanked 3 Times in 3 Posts
    Rep Power
    9
    I would store the input data in a variable so like:

    PHP Code:
    $datasent $_POST["txtTitle"]; 
    I would then have:

    PHP Code:
    print $datasent
    This should solve your problem.

  12. Thanks to My220x from:

    Hightower (23rd October 2008)

  13. #9
    CESIL's Avatar
    Join Date
    Nov 2006
    Location
    Hampshire
    Posts
    977
    Thank Post
    49
    Thanked 165 Times in 135 Posts
    Rep Power
    109
    I would store the text entered in a session variable, adding each new text entry to it. This can then be printed when the page reloads giving an audit trail of all text entered in that session.

  14. #10
    My220x's Avatar
    Join Date
    Feb 2008
    Location
    UK
    Posts
    257
    Blog Entries
    8
    Thank Post
    9
    Thanked 3 Times in 3 Posts
    Rep Power
    9
    Quote Originally Posted by cadjs View Post
    I would store the text entered in a session variable, adding each new text entry to it. This can then be printed when the page reloads giving an audit trail of all text entered in that session.
    Hightower said he/she wanted to print out what they have just entered not everything they have entered in that session.

  15. #11

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    493
    Thanked 688 Times in 443 Posts
    Rep Power
    237
    Thanks for all the help so far - I'm getting there. I have just one thing left to do, and need help again.

    I have managed to open, append and close a text file in the same location of the php files, but now need to open, append and close a text file that is stored on a different server.

    Can anybody help me?

    The code I have so far for this bit is:

    Code:
    $myFile = "whitelist.txt";
    $fh = fopen($myFile, 'a') or die("can't open file");
    $stringData = $_POST['txtAddress'];
    fwrite($fh, $stringData);           
    fwrite($fh, "\r\n");
    fclose($fh);
    The whitelist.txt bit needs to be pointing to \\SERVER\SHARE\whitelist.txt

    Thanks,

  16. #12
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,392
    Blog Entries
    41
    Thank Post
    77
    Thanked 77 Times in 64 Posts
    Rep Power
    33
    map the share to the server?

  17. #13

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    493
    Thanked 688 Times in 443 Posts
    Rep Power
    237
    I've tried doing that - I mapped it to G: and put in place G:\whitelist.txt but it said it had failed to open the file.

  18. #14
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,392
    Blog Entries
    41
    Thank Post
    77
    Thanked 77 Times in 64 Posts
    Rep Power
    33
    hmm a quick google says writing to windows network drives from php is massively problematic. you could maybe call up a local batch file that do the copying for you.

    or stick ftp on server so you can php > ftp instead.

  19. #15

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    493
    Thanked 688 Times in 443 Posts
    Rep Power
    237
    There's got to be a better way surely?

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Sysprep config – delete a text file
    By FN-GM in forum Windows
    Replies: 12
    Last Post: 16th September 2008, 12:57 PM
  2. Import a text file into a live web page
    By mrlegs in forum Web Development
    Replies: 9
    Last Post: 29th January 2008, 03:56 PM
  3. Replies: 4
    Last Post: 7th March 2007, 04:37 PM
  4. Batch: Text file -> Environment variable?
    By PiqueABoo in forum Scripts
    Replies: 5
    Last Post: 14th December 2006, 12:09 AM
  5. URLblacklist.com as text file
    By adamyoung in forum How do you do....it?
    Replies: 11
    Last Post: 9th February 2006, 03:35 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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