Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts

    writing to a text file and printing results onscreen

    Hi,,,


    I tried for about an hour to come up with a simple script to write info derived from a web form to a text file, then print the results onscreen with no luck.


    Unfortunately, I accidentally deleted my script, haha. But a search of the forums turned up something similar, except I used fputs() and then locked the file for writing then unlocked it.

    Code:
    <?php
    
    $file = $_POST['guest']; 
    $handle = fopen("test.txt", "w"); 
    fwrite($handle, $file); 
    fclose($handle);
    print $file;  
    
    ?>

    I used print $file to see if it was grabbing the variable value from the form and it was, but I can't get it to write it to the file....

    EDIT:


    I found a similar script to my original:

    Code:
    <?php 
    
    $fp = fopen('test.txt', 'w'); 
    $string = $_POST['guest'];
    
    flock($fp, LOCK_EX);
    fputs($fp, $string);
    flock($fp, LOCK_UN);
    fclose($fp);
    
    ?>

    Again, if i use print by itself, it works, but it won't write to the file.

    Code:
    <?php
    
    $strng = $_POST['guest'];
    print $strng;
    
    ?>
    Also if I do the following, it will write to the file, but not print:

    Code:
    <?php
    
    $file = "Some Text"; 
    $handle = fopen("test.txt", "w"); 
    fwrite($handle, $file); 
    fclose($handle);
    print $file;
     
    ?>





    any help will be appreciated..!
    Last edited by jamescover; 06-28-2007 at 03:34 AM.
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Use echo instead of print.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Use echo instead of print.



    Yeah, thanks...

    Well, it's sometimes the little things...

    This is what my form action tag looked like:

    action=""http://motox.ekigroup.com/guesttest/guestbook/processXML.php"


    Works perfectly now...
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    lol. Probably would have caught that if you had posted your form code.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    lol. Probably would have caught that if you had posted your form code.
    Well, I appreciate the effort...

    Doesn't take much to spoil the soup...


    -james
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "


  •  

    Posting Permissions

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