home *** CD-ROM | disk | FTP | other *** search
/ Practical Internet Web Designer 90 / PIWD90.iso / mac / contents / developer / tutorial_files / Pages88-89 / admin / delete.php < prev    next >
PHP Script  |  2003-12-15  |  3KB  |  104 lines

  1. <?php
  2. //connect to the database
  3. $conn = mysql_connect("localhost","root","pwd");
  4. //choose the cms db
  5.  
  6. mysql_select_db("cms", $conn);
  7. if ($_POST['btnDelete'] != "")
  8. {
  9.     //update the content
  10.     $sql = "DELETE FROM tblContent WHERE contentID = " . $_POST['contentID'];
  11.     if (mysql_query($sql, $conn))
  12.     {
  13.         $deleted = true;
  14.     }
  15. }
  16.  
  17. if ($_GET['btnSelect'] != "")
  18.  
  19. {
  20.     $delete = true;
  21.     //get the content
  22.     $article = mysql_query("SELECT contentTitle,contentText ,catID FROM tblContent WHERE contentID = " . $_GET['contentID'], $conn);
  23.     while ($articlerow = mysql_fetch_array($article)) {
  24.     $title = $articlerow['contentTitle'];
  25.     $content = $articlerow['contentText'];
  26.     $catID = $articlerow['catID'];
  27.     
  28.     //query the database for a list of categories - for the navigation menu
  29.     $result = mysql_query("SELECT catID, catName, catDesc FROM tblCat", $conn);
  30. }
  31.  
  32. }
  33. else
  34. {
  35.     //query the database for a list of content
  36.     $result = mysql_query("SELECT contentID, contentTitle FROM tblContent ORDER BY contentTitle", $conn);
  37. }
  38. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  39.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  40.  
  41. <html>
  42. <head>
  43. <title>CMS Admin</title>
  44. <link rel="stylesheet" type="text/css" href="../global.css" />
  45. </head>
  46.  
  47. <body>
  48. <div id="banner">
  49. <p> </p>
  50. </div>
  51. <div id="navigation">
  52. <ul class="main">
  53. <li><a href="add.php">Add Content</a></li>
  54. <li><a href="edit.php">Edit Content</a></li>
  55. <li><a href="delete.php">Delete Content</a></li>
  56. </ul>
  57. </div>
  58. <div id="content">
  59. <h1>Delete Content</h1>
  60. <?php
  61. if($deleted == true)
  62. {?>
  63. <p><strong>Your record has now been deleted from the database.</strong></p>
  64.  
  65. <?php
  66. }
  67. if($delete == true)
  68. {
  69. ?>
  70. <form method="post" action="delete.php">
  71. <p>Are you sure that you want to delete this record?</p>
  72. <p><input type="submit" name="btnDelete" value="Delete Record" />   <input type="button" name="btnQuit" value="Do not delete" onclick="window.location='delete.php';" /></p>
  73. <h2><?=$title?></h2>
  74. <p><?=$content?></p>
  75. <input type="hidden" name="contentID" id="contentID" value="<?=$_GET['contentID']?>" />
  76. </form>
  77.  
  78. <?php
  79. }
  80. else
  81. {
  82. ?>
  83. <p>Select the content you wish to delete from the database by selecting the corresponding radio button and clicking delete.</p>
  84. <form method="get" action="delete.php">
  85. <p>
  86. <?php
  87. while ($row = mysql_fetch_array($result)) {
  88.     print("<input type=\"radio\" name=\"contentID\" value=\"" . $row[contentID] . "\" /> ");
  89.     print($row[contentTitle] . "<br />\n");
  90. }
  91. ?>
  92. </p>
  93. <p><input type="submit" name="btnSelect" value="Delete Record" /></p>
  94. </form>
  95. <?php
  96. }
  97. ?>
  98.  
  99. </div>
  100. </body>
  101. </html>
  102.  
  103.  
  104.