home *** CD-ROM | disk | FTP | other *** search
/ Practical Internet Web Designer 90 / PIWD90.iso / mac / contents / developer / tutorial_files / Pages88-89 / admin / edit.php < prev    next >
PHP Script  |  2003-12-15  |  3KB  |  112 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['btnEdit'] != "")
  8. {
  9.     //update the content
  10.     $sql = "UPDATE tblContent SET contentTitle = '" . $_POST['contentTitle'] . "', contentText = '" . $_POST['contentText'] . "', catID = " . $_POST['catID'] . " WHERE contentID = " . $_POST['contentID'];
  11.     if (mysql_query($sql, $conn))
  12.     {
  13.         $updated = true;
  14.     }
  15. }
  16.  
  17. if ($_GET['edit'] == "true")
  18.  
  19. {
  20.     $edit = 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. }
  34. else
  35. {
  36.     //query the database for a list of content
  37.     $result = mysql_query("SELECT contentID, contentTitle FROM tblContent ORDER BY contentTitle", $conn);
  38. }
  39. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  40.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  41.  
  42. <html>
  43. <head>
  44. <title>CMS Admin</title>
  45. <link rel="stylesheet" type="text/css" href="../global.css" />
  46. </head>
  47.  
  48. <body>
  49. <div id="banner">
  50. <p> </p>
  51. </div>
  52. <div id="navigation">
  53. <ul class="main">
  54. <li><a href="add.php">Add Content</a></li>
  55. <li><a href="edit.php">Edit Content</a></li>
  56. <li><a href="delete.php">Delete Content</a></li>
  57. </ul>
  58. </div>
  59. <div id="content">
  60. <h1>Edit Content</h1>
  61. <?php
  62. if($edit == true)
  63. {
  64. ?>
  65.  
  66. <form method="post" action="edit.php">
  67. <p>Title:
  68. <br /><input name="contentTitle" id="contentTitle" class="text" value="<?=$title?>" /></p>
  69.  
  70. <p>Content:
  71. <br /><textarea name="contentText" id="contentText" class="largeText"><?=$content?></textarea></p>
  72.  
  73. <p>Category:
  74. <br /><select name="catID" id="catID">
  75. <?php
  76. while ($row = mysql_fetch_array($result)) {?>
  77. <option value="<?=$row['catID']?>"<?php
  78. if ($row['catID'] == $catID)
  79. {
  80.     print " selected=\"selected\"";
  81. }
  82. ?>><?=$row['catName']?></option>
  83. <?php
  84. }
  85. ?>
  86. </select></p>
  87. <input type="hidden" name="contentID" id="contentID" value="<?=$_GET['contentID']?>" />
  88. <p><input type="submit" name="btnEdit" value="Update Item" class="submit" /></p>
  89. </form>
  90.  
  91. <?php
  92. }
  93. else
  94. {
  95. ?>
  96. <p>Select the content you wish to edit from the list below by clicking on the title.</p>
  97. <ul>
  98. <?php
  99. while ($row = mysql_fetch_array($result)) {
  100.     print("<li><a href=\"edit.php?edit=true&contentID=" . $row[contentID] . "\">" . $row[contentTitle] . "</a></li>\n");
  101. }
  102. ?>
  103. </ul>
  104. <?php
  105. }
  106. ?>
  107. </div>
  108. </body>
  109. </html>
  110.  
  111.  
  112.