Miscellaneous
  Home arrow Miscellaneous arrow Creating a News System with PHP - Part 2
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS

Creating a News System with PHP - Part 2
By: Matt Wade
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-03-11

    Table of Contents:
  • Creating a News System with PHP - Part 2
  • Adding Options to the Display
  • Deleting an Item
  • Editing an Item
  • The Final Product

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating a News System with PHP - Part 2


    (Page 1 of 5 )

    This is part two in a series on creating a news system with PHP. This second installment will expand on our simple news system that only used a file for storage. We will continue with only a file, but add in editing and deletion functions.

    Well, I know in the first installment I said we would be adding database capabilities in this second installment. Sorry to disappoint, but I felt there were other things we needed to touch on before going to databases. Namely, the ability to delete and edit news that we have already added. If you haven't read the first tutorial in this series, I highly recommend you go check it out then come back to this one. I will be building on the foundations that we created in the first tutorial.

    Remember back to the first tutorial, we ended up with two scripts. One that actually displayed our news and one that we used to enter the news. What I plan to do in this tutorial is to only modify the administrative script. But, in order to delete or edit news, we need to see that news. So, I am going to add the news displaying script to the admin script. And then we will go from there. The two added together should look something like the following.

    <?
    echo "<H1><u>Current News</u></H1>\n";
    $data = file('news.txt');
    $data = array_reverse($data);
    foreach($data as $element) {
        $element = trim($element);
        $pieces = explode("|", $element);
        echo $pieces[2] . "<BR>" . "<b>Posted by " . $pieces[1] . " on " . $pieces[0] . "</b><BR><BR>";
    }
    echo "<HR>\n";
    echo "<H1><u>Add News</u></H1>\n";
    if($HTTP_POST_VARS['submit']) {
        if($HTTP_POST_VARS['password'] == 'pass') {
            if(!$HTTP_POST_VARS['name']) {
                echo "You must enter a name";
                exit;
            }
            if(!$HTTP_POST_VARS['news']) {
                echo "You must enter some news";
                exit;
            }
            if(strstr($HTTP_POST_VARS['name'],"|")) {
                echo "Name cannot contain the pipe symbol - |";
                exit;
            }
            if(strstr($HTTP_POST_VARS['news'],"|")) {
                echo "News cannot contain the pipe symbol - |";
                exit;
            }
            $fp = fopen('news.txt','a');
            if(!$fp) {
                echo "Error opening file!";
                exit;
            }
            $line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
            $line .= "|" . $HTTP_POST_VARS['news'];
            $line = str_replace("\r\n","<BR>",$line);
            $line .= "\r\n";
            fwrite($fp, $line);
            if(!fclose($fp)) {
                echo "Error closing file!";
                exit;
            }
            echo "<b>News added!</b>\n";    
        } else {
            echo "Bad Password";
        }
    }

    ?>
    <FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry">
    Your name:<BR>
    <INPUT TYPE="text" SIZE="30" NAME="name"><BR>
    The News:<BR>
    <TEXTAREA NAME="news" COLS="40" ROWS="5"></TEXTAREA><BR><BR>
    News Password:<BR>
    <INPUT TYPE="password" SIZE="30" NAME="password"><BR>
    <INPUT TYPE="submit" NAME="submit" VALUE="Post it!"><BR>
    </FORM>

    Great, now that we have our "new" admin script. Let's get to doing something new with it.

    More Miscellaneous Articles
    More By Matt Wade


       · need an html output to see exactly what is happening
       · it is really annoying
       · Just a note that the final product doesn't show up in the pdf, so if you print out...
       · How would I make it post news from newest to oldest?
       · Forget I ever posted that, I didn't read through the whole thing. It says it in the...
       · I've gone through this tutorial and updated the HTTP_POST_VAR to $_POST and I can...
       · I've been playing with the code and just can't seem to get it to work. I kept...
     

    MISCELLANEOUS ARTICLES

    - Stopping CSRF Attacks in Your PHP Applicatio...
    - Quick and Dirty AJAX Tutorial
    - Flickr Puzzle Mashup
    - The PAVISE of Security
    - Creating a CAPTCHA with PHP
    - Sending SMS Thru HTTP
    - The Postal Fix - Part 2
    - Adding Mail with Exim
    - The Postal Fix - Part 1
    - Create Your Own Custom API
    - Adding Drop Shadows with PHP
    - Writing a Basic Authentication System in PHP
    - Overlapping Images with GD
    - Using Sockets in PHP
    - Dynamic CSS with PHP





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT