SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Enthusiast drnibbles's Avatar
    Join Date
    Oct 2001
    Location
    Australia
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Easy way to update for novice

    Hi

    My dad wants a page that i built for him, but lets say that he is not the smartest dad on the block. So i was thinking about doing a easy update page for him where he just enters text and somehow post it on the web and the php code can pick it up from the text file or something. Maybe i can use a news poster or so..

    But i'm not that good. Is there anyone out there who knows a good way of helping my dad out...

  2. #2
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this going to be done with or without usage of a database like mysql?

  3. #3
    SitePoint Enthusiast drnibbles's Avatar
    Join Date
    Oct 2001
    Location
    Australia
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I have a database sitting. Would it help

  4. #4
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, it can be done with or without a database. Having a database would just make life simpler

    If you decide to use a database:
    I'd make a page with a form that allows him to type up any news/story/etc. When he hits submit, insert or update it into a table in the database. On the web-front, just have the page pull up entries from the table.

    If you decide NOT to use a database:
    I'd have him open up a text file, but be consistent with the naming! (i.e. news.txt) Update the text file at will, upload when finished. On the web-front, simply read the file and output to the web.

  5. #5
    SitePoint Enthusiast drnibbles's Avatar
    Join Date
    Oct 2001
    Location
    Australia
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK so far so good. but if i have him do a text file doesn't it need to be with <BR> tags and such to have it look good when he types or does php parse it as it is. If he types and makes a break with the enter key does it become a break when published also..?

  6. #6
    SitePoint Enthusiast drnibbles's Avatar
    Join Date
    Oct 2001
    Location
    Australia
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I think that I would go with the database. I'll see if i can hang the code needed by myself and get it into the database table. Hmm I'll be back here if i get any problems... Thanks you all

  7. #7
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by drnibbles
    OK so far so good. but if i have him do a text file doesn't it need to be with <BR> tags and such to have it look good when he types or does php parse it as it is. If he types and makes a break with the enter key does it become a break when published also..?
    You will need to replace '\n' with '<br>' either with regex or str_replace() when outputting to the web. This goes for the plain text approach AND the database approach.

  8. #8
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can also use the PHP function nl2br to convert any line breaks in the text file to <br> tags. Incidentally, how many pages of the site will he need to be able to update? If it's only one or two then you'll probably be better off using text files (a database would be overkill in that situation) whereas if you want him to be able to continuously add new pages whenever he wants a database would probably be better.

  9. #9
    SitePoint Enthusiast drnibbles's Avatar
    Join Date
    Oct 2001
    Location
    Australia
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No it's gonna be only one news page so to speak.

    Drnibbles

  10. #10
    SitePoint Addict Viral's Avatar
    Join Date
    Nov 2001
    Location
    Washington DC
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    text file version

    For something this simple, I'd just use a text file.

    The easiest way is to have him keep a copy locally that he edits and uploads anytime he wants to make changes. As mentioned before, keep the name the same and always upload to the same place (overwrite the old version). The quickest way to keep formatting of the text file is with the use of PRE tags:

    PHP Code:
    <PRE>
    <? include "news.txt"?>
    </PRE>

  11. #11
    SitePoint Enthusiast allusion's Avatar
    Join Date
    Aug 2001
    Location
    San Francisco, CA
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What would be a good way to have the textfile editable on the web? I've been doing things with databases lately where a database is not necessary at all and I haven't found any good resources online for working with flatfiles.

  12. #12
    SitePoint Enthusiast drnibbles's Avatar
    Join Date
    Oct 2001
    Location
    Australia
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks everyone. The <PRE> tags did the trick and my dad is happy about this. He actually managed to ftp upload after me showing him how to. HE is also happy to be able to do something so cool as FTP. He brags about it to all his friends mind you he's 77yrs old

  13. #13
    SitePoint Addict Viral's Avatar
    Join Date
    Nov 2001
    Location
    Washington DC
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by allusion
    What would be a good way to have the textfile editable on the web? I've been doing things with databases lately where a database is not necessary at all and I haven't found any good resources online for working with flatfiles.
    Allusion, you could do something like this:
    PHP Code:
    <html>
    <body>
    <? 
    if ($submit):

       
    // Open file and write new Content
       
    $fp fopen("/inc/yourfile.txt""w");
       
    fwrite($fp$contents);
       
    fclose($fp);
       print 
    "File updated successfully.<BR>";
        
    else :
      
      
    // Open file and read contents into form
      
    $fp fopen("/inc/yourfile.txt""r");
      
    $contents fread($fp,1000000);
      
    fclose($fp);
      print 
    "
        <form action='
    $PHP_SELF' method='POST'>
        <textarea name='contents' cols='50' rows='10'>
    $contents</textarea><BR>
        <input type='submit'>"
    ;

    endif;
    ?>
    </body>
    </html>

    You could also make the filename a variable supplied in the query string so this could be resuable for editing multiple files.

    Hope this helps
    --Viral
    A computer without Windows is like a chocolate cake without mustard.

  14. #14
    SitePoint Enthusiast allusion's Avatar
    Join Date
    Aug 2001
    Location
    San Francisco, CA
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! Here's the code I ended up going with:
    PHP Code:
    <?php
    if ($submit != "") {

       
    // Open file and write new Content
       
    $fp fopen("where.txt""w");
       
    fwrite($fp$contents);
       
    fclose($fp);
       print 
    "File updated successfully.<BR>";
        
    } else {
      
      
    // Open file and read contents into form
      
    $fp fopen("where.txt""r");
      
    $contents fread($fp,1000000);
      
    fclose($fp);
      print 
    "
        <form action='
    $PHP_SELF' method='POST'>
        <input type='text' name='contents' value='
    $contents'><br>
        <input type='submit' value='Update Location'>
        <input type='hidden' name='submit' value='yes'>
        </form>"
    ;
    }
    ?>
    All I had to do was CHMOD where.txt to be writable and it was good to go . Thanks!

  15. #15
    SitePoint Addict Viral's Avatar
    Join Date
    Nov 2001
    Location
    Washington DC
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by allusion
    <input type='submit' value='Update Location'>
    <input type='hidden' name='submit' value='yes'>
    </form>";
    [/PHP]
    Oops! I did leave off the name field you can lose the hidden field and do this:

    <input type='submit' name='submit' value='Update Location'>

    then if ($submit) would work
    Sorry about that error. Glad it worked for you!

    --Viral
    A computer without Windows is like a chocolate cake without mustard.


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
  •