Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <meta charset = "utf-8">
- <link rel="stylesheet" type="text/css" href="mystyle.css">
- <style>
- .button {
- background-color: #4CAF50;
- border: none;
- color: white;
- padding: 30px 32px;
- text-align: center;
- text-decoration: none;
- display: inline-block;
- font-size: 16px;
- margin: 4px 2px;
- cursor: pointer;
- }
- </style>
- </head>
- <body>
- <?php
- require 'connect.php'; //using require will include the connect.php file each time it is called.
- /*
- Server side validation function.
- */
- function validation_check()
- {
- // Validation code for the different fields can go here.
- return true;
- }
- if (isset($_POST['id']) &&
- isset($_POST['title']) &&
- isset($_POST['author']) &&
- isset($_POST['year']) &&
- isset($_POST['isbn'])
- )
- {
- $id = assign_data($conn, 'id');
- $title = assign_data($conn, 'title');
- $author = assign_data($conn, 'author');
- $Year = assign_data($conn, 'year');
- $ISBN = assign_data($conn, 'isbn');
- // validation process
- $validation_passed = validation_check();
- if($validation_passed == TRUE)
- {
- echo"Record has been successfully updated";
- }
- else{
- echo"Error record hasn't been updated properly";
- }
- }
- ?>
- <form action=" " method="post">
- <label for="id"> Book id: </label> <br>
- <input type="text" name="id" value = ""> <br>
- <label for="title"> Book Title: </label> <br>
- <input type="text" name="title" value = ""> <br>
- <label for="author"> Author name:</label> <br>
- <input type="text" name="author" value = ""> <br>
- <label for="author"> Year:</label> <br>
- <input type="year" name="year" value = ""> <br>
- <label for="author">ISBN:</label> <br>
- <input type="text" name="isbn" value = ""> <br>
- <input type="submit" value="add record">
- <br>
- <p><?php if(isset($validation_error))
- { echo "<p><em>$validation_error</em></p>";} //show validation error messages if they exists.?></p>
- </form>
- <?php
- function assign_data($conn, $var)
- {
- return $conn->real_escape_string($_POST[$var]);
- }
- $query = "SELECT * FROM Library";
- $result = $conn->query($query);
- if (!$result) die ("Database access failed: " . $conn->error);
- $rows = $result->num_rows;
- ?>
- <p>Here is your Books list</p>
- <table>
- <tr>
- <th>Book id</th>
- <th>Title</th>
- <th>Author</th>
- <th>Year</th>
- <th>ISBN</th>
- </tr>
- <?php
- if ($result->num_rows >0)
- {
- while($row = $result->fetch_assoc())
- {
- echo "<tr>";
- echo "<td>".$row["id"]."</td>";
- echo "<td>".$row["title"]."</td>";
- echo "<td>".$row["author"]."</td>";
- echo "<td>".$row["isbn"]."</td>";
- echo "</tr>";
- }
- }
- else
- {
- echo "0 results";
- }
- ?>
- </table>
- <?php
- $conn->close();
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement