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

Erasing The Past - 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
So that takes care of adding new data to the database. Now, how about deleting it?

You'll remember, from the discussion of "list.php" a few pages back, that the script "delete.php" is passed a $id variable, which holds the unique database identifier for the selected news item. The script "delete.php" needs this identifier in order to delete the correct record from the database.

Here's the code that makes up "delete.php":

<?
// delete.php - delete a press release
?>

<!-- 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 = "DELETE FROM news WHERE id = '$id'";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());

// close database connection
mysql_close($connection);

// print result
echo "<font size=-1>Deletion successful. <a href=list.php>Go back to the
main menu</a>.</font>";
?>

<!-- page footer - snip -->
This is so simple it hardly requires any explanation. The ID passed to the script via the $id variable is used to construct and execute a DELETE query, which removes the corresponding record from the database. Short, sweet and quite efficient.

 
 
>>> 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: