+ 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
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242

    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. #2

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    18,529
    Thank Post
    527
    Thanked 2,648 Times in 2,049 Posts
    Blog Entries
    24
    Rep Power
    925
    This should tell you how to do it: PHP Tutorial - File Write

  3. Thanks to localzuk from:

    Hightower (23rd October 2008)

  4. #3

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    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?

  5. #4

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    Any ideas?

  6. #5
    budgester's Avatar
    Join Date
    Jan 2006
    Location
    Enfield, Middlesex
    Posts
    486
    Thank Post
    4
    Thanked 38 Times in 30 Posts
    Rep Power
    25
    Can you post some code to show how far you have got, then we can help you.

  7. #6

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    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

  8. #7

    tmcd35's Avatar
    Join Date
    Jul 2005
    Location
    Norfolk
    Posts
    6,069
    Thank Post
    902
    Thanked 1,013 Times in 825 Posts
    Blog Entries
    9
    Rep Power
    350
    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.

  9. Thanks to tmcd35 from:

    Hightower (23rd October 2008)

  10. #8
    My220x's Avatar
    Join Date
    Feb 2008
    Location
    UK
    Posts
    257
    Thank Post
    9
    Thanked 3 Times in 3 Posts
    Blog Entries
    8
    Rep Power
    14
    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.

  11. Thanks to My220x from:

    Hightower (23rd October 2008)

  12. #9

    CESIL's Avatar
    Join Date
    Nov 2006
    Location
    Hampshire
    Posts
    1,405
    Thank Post
    109
    Thanked 267 Times in 198 Posts
    Rep Power
    169
    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.

  13. #10
    My220x's Avatar
    Join Date
    Feb 2008
    Location
    UK
    Posts
    257
    Thank Post
    9
    Thanked 3 Times in 3 Posts
    Blog Entries
    8
    Rep Power
    14
    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.

  14. #11

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    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,

  15. #12
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,540
    Thank Post
    112
    Thanked 89 Times in 75 Posts
    Blog Entries
    47
    Rep Power
    41
    map the share to the server?

  16. #13

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    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.

  17. #14
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,540
    Thank Post
    112
    Thanked 89 Times in 75 Posts
    Blog Entries
    47
    Rep Power
    41
    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.

  18. #15

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    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, 01: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
  •