1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Add New DJ</title>
  6. <style type="text/css">
  7. .error {font-family: "courier new"; color: red; font-size: 10pt;}
  8. </style>
  9. </head>
  10.  
  11. <body>
  12. <?php
  13. //include 'include\db.inc.php';
  14. $name = $_POST['name'];
  15. $age = $_POST['age'];
  16. $location = $_POST['location'];
  17. $intrests = $_POST['intrests'];
  18. $yearsofmixing = $_POST['yearsofmixing'];
  19. $playedat = $_POST['playedat'];
  20. $msn = $_POST['msn'];
  21. $email = $_POST['email'];
  22.  
  23. // Validation Routine
  24. $error = 0;
  25. $error_mes = '';
  26. if (strlen($_POST['name']) < 1) {$error = $error + 1; $error_mes .= "Sorry, no name entered\n";}
  27. if (strlen($_POST['age']) < 1) {$error = $error + 1; $error_mes .= "Sorry, no age entered\n";}
  28. if (strlen($_POST['location']) < 1) {$error = $error + 1; $error_mes .= "Sorry, no location entered\n";}
  29. if (strlen($_POST['intrests']) < 1) {$error = $error + 1; $error_mes .= "Sorry, no interests entered\n";}
  30. if (strlen($_POST['yearsofmixing']) < 1) {$error = $error + 1; $error_mes .= "Sorry, no years of mixing entered\n";}
  31. if (strlen($_POST['playedat']) < 1) {$error = $error + 1; $error_mes .= "Sorry, no places played at entered\n";}
  32. // if (strlen($_POST['msn']) < 1) {$error = $error + 1; $error_mes .= "Sorry, no msn name entered\n";} // This isn't an error --- is it?
  33. if (strlen($_POST['email']) < 1) {$error = $error + 1; $error_mes .= "Sorry, no email entered\n";}
  34.  
  35. if ($error >= 1) {;}
  36. else { // If no errors, enter data into database
  37. $sql = "INSERT INTO dj SET
  38. name='$name',
  39. age='$age',
  40. location='$location',
  41. intrests='$intrests',
  42. yearsofmixing='$yearsofmixing',
  43. playedat='$playedat',
  44. msn='$msn',
  45. email='$email'";
  46. if (@mysql_query($sql)) {
  47. echo '<p>New DJ Added! Thank you.</p>';
  48. } else {
  49. echo '<p>Database Error - New DJ not Added</p>';
  50. }
  51. }
  52. ?>
  53. <?php
  54. if ($_POST){
  55. if ($error >= 1)
  56. { // Prints any errors at the beginning of the page
  57. // echo "<PRE>";
  58. // echo "<span style=\"color: red;\">Errors!!!\n\n";
  59. // echo $error_mes;
  60. // echo "</span>";
  61. // echo "</PRE>";
  62. }
  63. }
  64. ?>
  65. <?php if ($error > 0) { ?>
  66. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  67. <p>Enter the new DJ Information: </p>
  68. <label for="name">Enter DJ Name:<br />
  69. <input type="text" name="name" id="name" value="<?php if (strlen($name) > 0) {echo $name;} ?>" /></label><br />
  70.  
  71. <span id="error_name" class="errormessage">
  72. <?php if ($_POST && strlen($_POST['name']) < 1) {echo "<P class=\"error\">No name entered.</P>";} ?>
  73. </span>
  74.  
  75. <label for="age">Enter DJ Age:<br />
  76. <input type="text" name="age" id="age" value="<?php if (strlen($age) > 0) {echo $age;} ?>" /></label><br />
  77.  
  78. <span id="error_age" class="errormessage">
  79. <?php if ($_POST){ if (preg_match('/^[0-9]+$/', $age)) {;} else {echo "<P class=\"error\">Age must be digits only.</P>";} } ?>
  80. </span>
  81.  
  82. <label for="location">Enter DJ Location:<br />
  83. <input type="text" name="location" id="location" value="<?php if (strlen($location) > 0) {echo $location;} ?>" /> </label><br />
  84.  
  85. <span id="error_location" class="errormessage">
  86. <?php if ($_POST && strlen($_POST['location']) < 1) {echo "<P class=\"error\">No location entered.</P>";} ?>
  87. </span>
  88.  
  89. <label for="intrests">Enter DJ Intrests:<br />
  90. <textarea name="intrests" rows="10" cols="25" id="intrests"><?php if (strlen($intrests) > 0) {echo $intrests;} ?></textarea></label><br />
  91.  
  92. <span id="error_intrests" class="errormessage">
  93. <?php if ($_POST && strlen($_POST['intrests']) < 1) {echo "<P class=\"error\">No interests entered.</P>";} ?>
  94. </span>
  95.  
  96. <label for="mixing">Enter DJ Years of Mixing:<br />
  97. <input type="text" name="yearsofmixing" id="mixing" value="<?php if (strlen($yearsofmixing) > 0) {echo $yearsofmixing;} ?>" /></label><br />
  98.  
  99. <span id="error_mixing" class="errormessage">
  100. <?php if ($_POST){ if (preg_match('/^[0-9]+$/', $yearsofmixing)) {;} else {echo "<P class=\"error\">Years of mixing must be digits only.</P>";} } ?>
  101. </span>
  102.  
  103. <label for="playedat">Enter DJ Played At:<br />
  104. <textarea name="playedat" rows="10" cols="25" id="playedat"><?php if (strlen($playedat) > 0) {echo $playedat;} ?></textarea></label><br />
  105.  
  106. <span id="error_played" class="errormessage">
  107. <?php if ($_POST && strlen($_POST['playedat']) < 1) {echo "<P class=\"error\">No places played at entered.</P>";} ?>
  108. </span>
  109.  
  110. <p>Enter Contact Details: </p>
  111. <label for="msn"> Enter DJ MSN:<br />
  112. <input type="text" name="msn" id="msn" value="<?php if (strlen($msn) > 0) {echo $msn;} ?>" /></label><br />
  113.  
  114. <span id="error_msn" class="errormessage">
  115. <?php
  116.  
  117. if (strlen($msn) > 0){ // MSN email address not required
  118. // This regex from http://www.smartwebby.com/PHP/emailvalidation.asp
  119. if (ereg("^[^@ ]+@[^@ ]+\.[^@ ]+$",$msn)) {;} else {echo "<P class=\"error\">This is invalid MSN email address.</P>";}
  120. }
  121. ?>
  122. </span>
  123.  
  124. <label for="mail">Enter DJ E-Mail:<br />
  125. <input type="text" name="email" id="mail" value="<?php if (strlen($email) > 0) {echo $email;} ?>" /></label><br />
  126.  
  127. <span id="error_email" class="errormessage">
  128. <?php
  129.  
  130. if ($_POST){
  131. // This regex from http://www.smartwebby.com/PHP/emailvalidation.asp
  132. if (ereg("^[^@ ]+@[^@ ]+\.[^@ ]+$",$email)) {;} else {echo "<P class=\"error\">This is invalid email address.</P>";}
  133. }
  134. ?>
  135. </span>
  136.  
  137. <input type="submit" name="add_dj" value="Add DJ" id="adddj" />
  138.  
  139. </form>
  140.  
  141. <?php }?>
  142. </body>
  143. </html>