Advertisement
Guest User

Untitled

a guest
May 20th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 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. .button {
  7. background-color: #4CAF50;
  8. border: none;
  9. color: white;
  10. padding: 30px 32px;
  11. text-align: center;
  12. text-decoration: none;
  13. display: inline-block;
  14. font-size: 16px;
  15. margin: 4px 2px;
  16. cursor: pointer;
  17. }
  18. </style>
  19. </head>
  20.  
  21.  
  22. <body>
  23.  
  24. <?php
  25.  
  26. require 'connect.php'; //using require will include the connect.php file each time it is called.
  27.  
  28.  
  29. /*
  30. Server side validation function.
  31. */
  32. function validation_check()
  33. {
  34.  
  35. // Validation code for the different fields can go here.
  36.  
  37.  
  38. return true;
  39. }
  40.  
  41.  
  42.  
  43. if (isset($_POST['id']) &&
  44. isset($_POST['title']) &&
  45. isset($_POST['author']) &&
  46. isset($_POST['year']) &&
  47. isset($_POST['isbn'])
  48. )
  49.  
  50. {
  51.  
  52. $id = assign_data($conn, 'id');
  53. $title = assign_data($conn, 'title');
  54. $author = assign_data($conn, 'author');
  55. $Year = assign_data($conn, 'year');
  56. $ISBN = assign_data($conn, 'isbn');
  57.  
  58.  
  59.  
  60. // validation process
  61.  
  62. $validation_passed = validation_check();
  63.  
  64. if($validation_passed == TRUE)
  65. {
  66. echo"Record has been successfully updated";
  67.  
  68.  
  69. }
  70. else{
  71. echo"Error record hasn't been updated properly";
  72. }
  73. }
  74. ?>
  75.  
  76.  
  77.  
  78. <form action=" " method="post">
  79.  
  80. <label for="id"> Book id: </label> <br>
  81. <input type="text" name="id" value = ""> <br>
  82.  
  83. <label for="title"> Book Title: </label> <br>
  84. <input type="text" name="title" value = ""> <br>
  85.  
  86. <label for="author"> Author name:</label> <br>
  87. <input type="text" name="author" value = ""> <br>
  88.  
  89. <label for="author"> Year:</label> <br>
  90. <input type="year" name="year" value = ""> <br>
  91.  
  92. <label for="author">ISBN:</label> <br>
  93. <input type="text" name="isbn" value = ""> <br>
  94.  
  95. <input type="submit" value="add record">
  96.  
  97. <br>
  98. <p><?php if(isset($validation_error))
  99. { echo "<p><em>$validation_error</em></p>";} //show validation error messages if they exists.?></p>
  100.  
  101. </form>
  102.  
  103.  
  104. <?php
  105.  
  106. function assign_data($conn, $var)
  107. {
  108. return $conn->real_escape_string($_POST[$var]);
  109. }
  110.  
  111.  
  112. $query = "SELECT * FROM Library";
  113. $result = $conn->query($query);
  114. if (!$result) die ("Database access failed: " . $conn->error);
  115.  
  116. $rows = $result->num_rows;
  117.  
  118. ?>
  119.  
  120. <p>Here is your Books list</p>
  121.  
  122. <table>
  123. <tr>
  124. <th>Book id</th>
  125. <th>Title</th>
  126. <th>Author</th>
  127. <th>Year</th>
  128. <th>ISBN</th>
  129. </tr>
  130.  
  131. <?php
  132. if ($result->num_rows >0)
  133. {
  134. while($row = $result->fetch_assoc())
  135. {
  136. echo "<tr>";
  137. echo "<td>".$row["id"]."</td>";
  138. echo "<td>".$row["title"]."</td>";
  139. echo "<td>".$row["author"]."</td>";
  140. echo "<td>".$row["isbn"]."</td>";
  141. echo "</tr>";
  142. }
  143. }
  144. else
  145. {
  146. echo "0 results";
  147. }
  148. ?>
  149.  
  150. </table>
  151.  
  152.  
  153.  
  154. <?php
  155. $conn->close();
  156. ?>
  157.  
  158. </body>
  159. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement