Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: Save form data in a txt file with current date in file name

  1. #11
    Join Date
    Aug 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I cant get this to work, I put the code inside html, head and body tags and saved it as .php file it just displays a page of the code and nothing else.

    How did you test it. Am I doing something wrong

  2. #12
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    damn spam...
    Edit: no more spam! thanks

    Quote Originally Posted by trazix View Post
    I cant get this to work, I put the code inside html, head and body tags and saved it as .php file it just displays a page of the code and nothing else.

    How did you test it. Am I doing something wrong
    The actual php code displays? Check your <?php ?> tags and make sure you have all the php code contained within. You also need to create a subdirectory named "write" in the same directory as this file. Otherwise, I'm not sure what the problem would be. The code I posted is *exactly* what I have online here.
    Last edited by traq; 06-21-2009 at 03:57 AM.

  3. #13
    Join Date
    Aug 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Got the web page to display but when i click Submit I get this message

    Comments submitted so far:
    Fatal error: Call to undefined function filter_var() in /www/htdocs/TEST.php on line 50

    Not sure what could be wrong your code is just copy and pasted to my file.

  4. #14
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    What version of PHP do you have installed? If it is below PHP 5, then filter_var will not work.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #15
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    yeah. contact your webhost; sometimes they can upgrade. 1and1, for example, advertises php5 but runs php4 by default and you have to use .htaccess to switch to php5.

    alternatively, replace this line:
    PHP Code:
    $filecontent filter_var($RAWfilecontentFILTER_SANITIZE_STRING); 
    with this:
    PHP Code:
    $filecontent htmlentities($RAWfilecontent); 
    which will also make the user input safer, but won't look as nice. For example, if someone tried to attack your site by saving a message like this:
    Code:
    <script type="text/javascript">
         window.location = "www.endlesspopups.com"
    </script>
    FILTER_SANITIZE_STRING would strip the tags (preventing the code from running) and display it like this:
    Code:
    window.location = "www.endlesspopups.com"
    and htmlentities would encode the < > characters (preventing the code from running) and display the original message just as you see it above.

  6. #16
    Join Date
    Aug 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It'S PHP Version 5.1.6 , I am using a freehost service just for testing and learning.

    I modified that line and it works, but the posted messages are not in the order they were posted it semes to be random.

  7. #17
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    If you're running php5, then filter_var ought to work (and would be preferable, IMO). Likewise, I don't know why the messages would be being displayed in random order. Would you link to your test page?

  8. #18
    Join Date
    Aug 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

  9. #19
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    ... no idea.
    it does seem to be random. but it seems to always be in the same random order (except for each new submission, of course).

  10. #20
    Join Date
    Aug 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have come up with a solution to show the files from the last one posted, first i open the filecount.txt file and get the number stored in it, then i use it to count backwards and then include the .txt file on the page. Here is the code

    PHP Code:
    <?php
    $filename
    "filecount.txt" ;
    $fd fopen ($filename "r") or die ("Can't open $filename") ;
    $fstring fread ($fd filesize ($filename)) ;

    include(
    'write/'.--$fstring.'.txt');

    include(
    'write/'.--$fstring.'.txt');

    include(
    'write/'.--$fstring.'.txt');

    include(
    'write/'.--$fstring.'.txt');

    include(
    'write/'.--$fstring.'.txt');

    include(
    'write/'.--$fstring.'.txt');

    include(
    'write/'.--$fstring.'.txt');

    include(
    'write/'.--$fstring.'.txt');

    include(
    'write/'.--$fstring.'.txt');

    include(
    'write/'.--$fstring.'.txt');

    include(
    'write/'.--$fstring.'.txt');

    include(
    'write/'.--$fstring.'.txt');

    fclose($fd) ;

    ?>
    And a link to it
    http://yabadabadoo.blackapplehost.co.../Showfiles.php

    Now the problem here i all the text is bunched together.
    What i would like is to have a break between each file include, I tryed putting in echo <br> but nothing would display.

    Also the code is long I am sure a loop or something could be writen to do what all the above includes are doing, If posible i would like it to just display the last 20 files posted with a link then for the next 20 and so on, I hope somebody is up to this challenge a my php is very basic and getting the above code working was not easy for me.
    Last edited by trazix; 06-28-2009 at 11:49 AM.

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
  •