Home arrow PHP arrow Page 5 - Building A Quick-And-Dirty PHP/MySQL Publishing System

Admin Ahoy! - PHP

Looking to quickly add a dynamic news page to your corporate orpersonal Web site? This article shows you how, combining PHP's rapidapplication development capabilities with a MySQL database to create aprimitive news publishing system and administration module in just underfour hours.

TABLE OF CONTENTS:
  1. Building A Quick-And-Dirty PHP/MySQL Publishing System
  2. A Little Slug-gish
  3. A Maniac Is Born
  4. Bedtime Stories
  5. Admin Ahoy!
  6. Splitting Up
  7. Erasing The Past
  8. Changing Things Around
  9. Game Over
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 44
March 12, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: