Advertisement
Guest User

Untitled

a guest
May 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. <html>
  2. <head>
  3. <meta charset = "utf-8">
  4. <link rel="stylesheet" type="text/css" href="mystyle.css">
  5. <style>
  6. </style>
  7. </head>
  8.  
  9.  
  10. <body>
  11. <style>
  12.  
  13. </style>
  14.  
  15.  
  16. <?php
  17.  
  18. require 'connect.php'; //using require will include the connect.php file each time it is called.
  19.  
  20.  
  21. /*
  22. Server side validation function.
  23. */
  24.  
  25. if(strlen($_POST['id']) > 20 ) { echo"ID too long!";
  26. return false;
  27. }
  28. else if(strlen($_POST['title']) > 30 )
  29. {
  30. echo"Book title too long!";
  31. return false;
  32. }
  33. else if(strlen($_POST['author']) > 10)
  34. {
  35. echo"No author submitted!";
  36. return false;
  37. }
  38. else if(strlen($_POST['year']) > 4)
  39. {
  40. echo"Year is too long!";
  41. return false;
  42. }
  43. else if(strlen($_POST['isbn']) ? ) { echo "ISBN not valid!";
  44. return false;
  45. }
  46. function validation_check()
  47. {
  48.  
  49. // Validation code for the different fields can go here.
  50. if(empty($_POST['id']))
  51. {
  52. echo"No id submitted!";
  53. return false;
  54. }
  55.  
  56. else if(empty($_POST['title']))
  57. {
  58. echo"No title submitted!";
  59. return false;
  60. }
  61. else if(empty($_POST['author']))
  62. {
  63. echo"No author submitted!";
  64. return false;
  65. }
  66. else if(empty($_POST['year']))
  67. {
  68. echo"No year submitted!";
  69. return false;
  70. }
  71. else if(empty($_POST['isbn']))
  72. {
  73. echo"No ISBN submitted!";
  74. return false;
  75. }
  76.  
  77. return true;
  78. }
  79.  
  80.  
  81.  
  82. if (isset($_POST['id']) &&
  83. isset($_POST['title']) &&
  84. isset($_POST['author']) &&
  85. isset($_POST['year']) &&
  86. isset($_POST['isbn'])
  87. )
  88.  
  89. {
  90.  
  91. $id = assign_data($conn, 'id');
  92. $title = assign_data($conn, 'title');
  93. $author = assign_data($conn, 'author');
  94. $Year = assign_data($conn, 'year');
  95. $ISBN = assign_data($conn, 'isbn');
  96.  
  97.  
  98.  
  99. // validation process
  100.  
  101.  
  102. $validation_passed = validation_check();
  103.  
  104. if($validation_passed == TRUE)
  105. {
  106. echo"Record has been successfully updated";
  107.  
  108.  
  109. }
  110. else{
  111. echo"Error record hasn't been updated properly";
  112. }
  113. }
  114. ?>
  115.  
  116.  
  117.  
  118. <form action=" " method="post">
  119.  
  120. <div class = "buttons">
  121.  
  122. <label for="id"> Book id: </label> <br>
  123. <input type="text" name="id" value = ""> <br>
  124. <input type="button" class="buttons" value="Delete Record"> <br>
  125.  
  126. <label for="title"> Book Title: </label> <br>
  127. <input type="text" name="title" value = ""> <br>
  128.  
  129. <label for="author"> Author name:</label> <br>
  130. <input type="text" name="author" value = ""> <br>
  131.  
  132. <label for="author"> Year:</label> <br>
  133. <input type="year" name="year" value = ""> <br>
  134.  
  135. <label for="author">ISBN:</label> <br>
  136. <input type="text" name="isbn" value = ""> <br>
  137.  
  138. <input type="submit" value="add record">
  139.  
  140. <br>
  141. <p>
  142. <?php
  143. if(isset($validation_error))
  144. { echo "<p><em>$validation_error</em></p>";} //show validation error messages if they exists.?></p>
  145.  
  146. </form>
  147.  
  148.  
  149. <?php
  150.  
  151. function assign_data($conn, $var)
  152. {
  153. return $conn->real_escape_string($_POST[$var]);
  154. }
  155.  
  156.  
  157. $query = "SELECT * FROM Library";
  158. $result = $conn->query($query);
  159. if (!$result) die ("Database access failed: " . $conn->error);
  160.  
  161. $rows = $result->num_rows;
  162.  
  163. ?>
  164.  
  165. <p>Here is your Books list</p>
  166.  
  167. <table>
  168. <tr>
  169. <th>Book id</th>
  170. <th>Title</th>
  171. <th>Author</th>
  172. <th>Year</th>
  173. <th>ISBN</th>
  174. </tr>
  175.  
  176. <?php
  177. if ($result->num_rows >0)
  178. {
  179. while($row = $result->fetch_assoc())
  180. {
  181. echo "<tr>";
  182. echo "<td>".$row["id"]."</td>";
  183. echo "<td>".$row["title"]."</td>";
  184. echo "<td>".$row["author"]."</td>";
  185. echo "<td>".$row["year"]."</td>";
  186. echo "<td>".$row["isbn"]."</td>";
  187. echo "</tr>";
  188. }
  189. }
  190. else
  191. {
  192. echo "0 results";
  193. }
  194. ?>
  195.  
  196. </table>
  197.  
  198.  
  199.  
  200. <?php
  201. $conn->close();
  202. ?>
  203.  
  204. </body>
  205. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement