PHP
  Home arrow PHP arrow Page 5 - Building A Quick-And-Dirty PHP/MySQL P...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
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? 
PHP

Building A Quick-And-Dirty PHP/MySQL Publishing System
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 42
    2002-03-12

    Table of Contents:
  • Building A Quick-And-Dirty PHP/MySQL Publishing System
  • A Little Slug-gish
  • A Maniac Is Born
  • Bedtime Stories
  • Admin Ahoy!
  • Splitting Up
  • Erasing The Past
  • Changing Things Around
  • Game Over

  • 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


    Building A Quick-And-Dirty PHP/MySQL Publishing System - Admin Ahoy!


    (Page 5 of 9 )

    At this point in time, I do not really have a simple way to update the database with new information. In order to insert or edit information into the database, I need to know SQL and have access to a MySQL client. This works fine for me, the developer - but remember what the customer said about wanting something simple and easily usable?

    Obviously, I cannot ask the customer to learn SQL just to update the database. So I need to develop a simple, friendly interface that she can use to update the database. Which brings me to the second part of the development effort - the administration module.

    Based on the functions described to me by the customer, it seems clear (to me, at least) that I will need the following four scripts:

    "list.php" - the starting point for the administration module, which lists all press releases currently in the database and allows the administrator to select an individual record for an edit or delete operation;

    "edit.php" - the script which allows the administrator to update a selected record;

    "delete.php" - the script which allows the administrator to delete the selected record;

    "add.php" - the script which allows the administrator to add a new record.

    These scripts are stored within the "admin" directory in the source code archive. When the application is finally uploaded to the customer's Web site, this directory will need to be protected against unauthorized usage via Apache's HTTP authentication mechanism (for more information on how this works, take a look at the links at the end of this article).

    Let's look at each of these in turn.{mospagebreak title=A List In Time} First up, "list.php". As described above, it simply displays a list of all press releases currently stored in the database, with links to the scripts to actually edit or delete them. Here goes:

    <?
    // list.php - display list of all press releases
    ?>

    <!-- page header - snip -->

    <?
    // includes
    include("../conf.php");
    include("../functions.php");

    // open database connection
    $connection = mysql_connect($host, $user, $pass) or die ("Unable to
    connect!");

    // select database
    mysql_select_db($db) or die ("Unable to select database!");

    // generate and execute query
    $query = "SELECT id, slug, timestamp FROM news ORDER BY timestamp DESC";
    $result = mysql_query($query) or die ("Error in query: $query. " .
    mysql_error());

    // if records present
    if (mysql_num_rows($result) > 0)
    {
    // iterate through resultset
    // print title with links to edit and delete scripts
    while($row = mysql_fetch_object($result))
    {
    ?>
    <font size="-1"><b><? echo $row->slug; ?></b> [<? echo
    formatDate($row->timestamp); ?>]</font>
    <br>
    <font size="-2"><a href="edit.php?id=<? echo $row->id; ?>">edit</a> | <a
    href="delete.php?id=<? echo $row->id; ?>">delete</a></font>
    <p>
    <?
    }
    }
    // if no records present
    // display message
    else
    {
    ?>
    <font size="-1">No press releases currently available</font><p>
    <?
    }

    // close connection
    mysql_close($connection);
    ?>
    <font size="-2"><a href="add.php">add new</a></font>

    <!-- page footer - snip -->
    As you can see, this is almost identical to the code used in the other "list.php" - and well it should be, since it performs a nearly-identical function. Here's what it looks like:



    Pay special attention to the links to "edit.php" and "delete.php" in the script above; you'll see that each of these scripts is passed an additional $id variable, which contains the unique record identifier for that particular item.

    <font size="-2"><a href="edit.php?id=<? echo $row->id; ?>">edit</a> | <a
    href="delete.php?id=<? echo $row->id; ?>">delete</a></font>
    Don't worry too much about why I'm doing this - all will be explained shortly.

    More PHP Articles
    More By icarus, (c) Melonfire


     

       

    PHP ARTICLES

    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview
    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway