SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    Next stop: PHP! Marina's Avatar
    Join Date
    Apr 2001
    Location
    Sweden
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need a text submitting PHP script

    Iím designing a personal site for my boyfriendís little sister. She would like to display the latest news in her life on the front page. See an example at www.dreamweaverfever.com
    Iím going to make a password protected page with a submit form for her. Then she just have to write the news in the textarea and press the submit button.

    I need a PHP3 script that places the content of the form in a table on the index.htm page. The form consists of one textfield (name=ĒnyheterĒ).
    - The script should insert the date above every entry (DD.MM.YYYY).
    - The .datum (external) CSS class should be applied to the date.
    - The .texten (external) CSS class should be applied to the rest of the text.
    - When she presses the submit button the text should be stored in nyheter.txt file.
    - Only the last five entries should be displayed in the table on the index.htm page.

    If itís not too complicated, could you please show me how to make this script?

  2. #2
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <form name="textform" action="updatenyheter.php" method="post">
    <textarea name="form_text"></textarea><br />
    <input type="submit" name="submit" value="Publish !" />
    </form>
    Then, updatenyheter.php goes:
    PHP Code:
    //EDIT: erroneous code here, see below for right code 
    In the front page, put something like

    PHP Code:
    <table>
    <?php include("nyheter.txt"); ?>
    </table>

    Well, it still lacks the 'last 5 posts' feature, this is something that I'm still working on for the text version of my mysql news script...

    Hope it helps, though
    Last edited by Michel V; Jul 20, 2001 at 10:17.
    [blogger: zengun] [blogware contributor: wordpress]

  3. #3
    Next stop: PHP! Marina's Avatar
    Join Date
    Apr 2001
    Location
    Sweden
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm forever grateful to you Shin Ma! Thank you! If someone wants to add the "last 5 posts" feature please do.

  4. #4
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, ready-to-use solutions are available for this task, such as www.Blogger.com, or if your friend has access to a MySQL db, there are several good news script, such as Skunk's ssNews (http://simon.incutio.com/news.php), or b2 (http://b2.dayzero.org).
    As I said, I'm preparing a textfiles version of b2, but I'm still hitting my head on the 'display last X posts' feature...
    [blogger: zengun] [blogware contributor: wordpress]

  5. #5
    Next stop: PHP! Marina's Avatar
    Join Date
    Apr 2001
    Location
    Sweden
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sure you will find a solution. Thank you once again.

  6. #6
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just edited the code up there, just 2 lines changed, but they're useful for this:

    PHP Code:
    //Erroneous code - see below for right code 
    Almost straight out of the manual
    I haven't tested this code, but it should work.
    Last edited by Michel V; Jul 20, 2001 at 10:16.
    [blogger: zengun] [blogware contributor: wordpress]

  7. #7
    Next stop: PHP! Marina's Avatar
    Join Date
    Apr 2001
    Location
    Sweden
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll gladly test it for you!

  8. #8
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's full of mistakes ! Wait, I'm orrecting everything. Ah, what happens when you 'think' the code :roll:
    [blogger: zengun] [blogware contributor: wordpress]

  9. #9
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK just got back from the office, here's the completely clean working code:

    First, the page with the form:
    Code:
    <form name="textform" action="updatenyheter.php" method="post">
    <textarea name="form_text"></textarea><br />
    <input type="submit" name="submit" value="Publish !" />
    </form>
    Then, updatenyheter.php:
    PHP Code:
    <?php

    $form_text 
    eregi_replace("\r\n","\n",$form_text);
    $form_text nl2br($form_text);

    $s="<tr><td><p class=\"datum\">".date("d.m.Y")."</p>";
    $s.="<p class=\"texten\">".$form_text."</p>";
    $s.="</td></tr>\n";
    $f=fopen('nyheter.txt','a+');
    fwrite($f,$s);
    fclose($f);

    header ("Location: index.php");

    ?>
    Then, index.php, to display the 5 last entries:
    PHP Code:
    <table>
    <?php
    $file 
    "nyheter.txt";
    $f fopen($file"r");
    $s fread($f,filesize($file));
    fclose($f);
    $posts=explode("\n",$s);
    $posts=array_reverse($postsFALSE);
    for(
    $i=0$i<5$i++) {
    echo 
    $posts[$i];
    }
    ?>
    </table>
    I tested it, it works now
    (first you may want to create a blank nyheter.txt file, and ChMod it 777, or any other ChMod that makes it writeable by the webserver)
    [blogger: zengun] [blogware contributor: wordpress]

  10. #10
    Next stop: PHP! Marina's Avatar
    Join Date
    Apr 2001
    Location
    Sweden
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for taking the time to write the script Shin Ma! I'll probably post some questions about it later. (I'm really new to PHP but eager to learn.) You're No 1 at my PHP guru list right now.


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
  •