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

  1. <?php
  2. //connect to the database
  3. $conn = mysql_connect("localhost","root","pwd");
  4. //choose the cms db
  5. mysql_select_db("cms", $conn);
  6.  
  7. if ($_POST['btnAdd'] != "") 
  8. {
  9.     $sql = "INSERT INTO tblContent (contentTitle, contentText, catID) VALUES ('" . $_POST['contentTitle'] . "','" . $_POST['contentText'] . "'," . $_POST['catID'] . ")";
  10.     if (mysql_query($sql, $conn))
  11.     {
  12.         $new = true;
  13.     }
  14. }
  15.  
  16. //query the database for a list of categories
  17. $result = mysql_query("SELECT catID, catName, catDesc FROM tblCat", $conn);
  18. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  19.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  20.  
  21. <html>
  22. <head>
  23. <title>CMS Homepage</title>
  24. <link rel="stylesheet" type="text/css" href="../global.css" />
  25. </head>
  26.  
  27. <body>
  28. <div id="banner">
  29. <p> </p>
  30. </div>
  31. <div id="navigation">
  32. <ul class="main">
  33. <li><a href="add.php">Add Content</a></li>
  34. <li><a href="edit.php">Edit Content</a></li>
  35. <li><a href="delete.php">Delete Content</a></li>
  36. </ul>
  37. </div>
  38. <div id="content">
  39. <h1>Add Content</h1>
  40. <?php
  41. if($new == true)
  42. {?>
  43. <p><strong>Your new article has been added.</strong></p>
  44. <?php
  45. }
  46. ?>
  47. <form method="post" action="add.php">
  48. <p>Title:
  49. <br /><input name="contentTitle" id="contentTitle" class="text" /></p>
  50. <p>Content:
  51. <br /><textarea name="contentText" id="contentText" class="largeText"></textarea></p>
  52. <p>Category:
  53. <br /><select name="catID" id="catID">
  54. <?php
  55. while ($row = mysql_fetch_array($result)) {?>
  56. <option value="<?=$row['catID']?>"><?=$row['catName']?></option>
  57. <?php
  58. }
  59. ?>
  60. </select></p>
  61. <p><input type="submit" name="btnAdd" value="Add Item" class="submit" /></p>
  62. </form>
  63. </div>
  64. </body>
  65. </html>
  66.  
  67.  
  68.