Content Management Systems—Article Deleting
Article Content Management System
Article Deleting
Okay, here is the entire article deleting PHP script. This script gets you to input an article title to search for in the "articles" MySQL table and if it finds it, it deletes the article/record. If it doesn't find the title, you get a message saying so. Delete is a simple SQL keyword and DELETE FROM WHERE are the keywords that will do the job—as long as you know the exact title to delete, you're in business. It deletes one record/article and that's that.
SAVE THIS PAGE AS: cms-delete-articles.php
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>Delete Articles—Content Management System (CMS)</TITLE>
<meta name="description" content="Delete Articles—Content Management System (CMS)">
<meta name="keywords" content="Delete Articles,Content Management System,Content Management System Articles,php,CMS,javascript, dhtml, DHTML">
<style type="text/css">
BODY {margin-left:0; margin-right:0; margin-top:0;text-align:left;background-color:#ddd}
p, li {font:13px Verdana; color:black;text-align:left;text-indent:2em;margin-bottom:-1em}
h1 {font:bold 28px Verdana; color:black;text-align:center}
h2 {font:bold 24px Verdana;text-align:center}
h3 {font:bold 15px Verdana;}
.title {position:absolute;top:10px;left:10px;width:962px}
.form {margin-left:70px}
.info {position:absolute;top:238px;left:2px;width:160px;background-color:#bbb;border:1px solid blue;padding:5px}
</style>
</head>
<body>
<div class='title'>
<h1>Delete Articles—Content Management System (CMS)</h1>
<form class='form' method="post" action="cms-delete-articles.php">
<table width="700" border="0" cellpadding="2" cellspacing="2" align="center">
<tr>
<td width="100" align=right>Title </td>
<td><input name="title" type="text" size="100"></td>
<tr>
<td> </td><td><input name="retrieve" type="submit" value="Delete Article from DB">
<input name="reset" type="reset" value="Reset"></td></tr>
</table>
</form>
</div>
<?php
include_once"config.php";
$T=mysql_real_escape_string($_POST['title']);if(strlen($T)>2){
mysql_query("DELETE FROM articles WHERE title='$T'") or die('Error ,deleting failed');
$rc = mysql_affected_rows();
unset($T);
if ($rc>0){$T='';echo '<script language="javascript">alert("The deleting was successfully accomplished.");</script>';}
else{echo '<script language="javascript">alert("This title does not exist. Please try again.")</script>;';unset($T);}
}
mysql_close();
?>
<div id='info' class='info'>No single or double quotes or Enter/Return allowed in titles. Use letters, numbers, spaces and these: <B> , . ) ? : ( ; _ - ! </b> in title. <br></div>
<?php include("navigation.html"); ?>
</body>
</html>