Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <?php
- require 'database.php';
- $id = null;
- if ( !empty($_GET['id'])) {
- $id = $_REQUEST['id'];
- }
- if ( null==$id ) {
- header("Location: adminpage.php");
- }
- if ( !empty($_POST)) {
- // keep track validation errors
- $ISBN_noError = null;
- $book_titleError = null;
- $author_nameError = null;
- $year_publishedError = null;
- $priceError = null;
- $publisherError = null;
- $genreError = null;
- // keep track post values
- $ISBN_no = $_POST['ISBN_no'];
- $book_title = $_POST['book_title'];
- $author_name = $_POST['author_name'];
- $year_published = $_POST['year_published'];
- $price = $_POST['price'];
- $publisher = $_POST['publisher'];
- $genre = $_POST['genre'];
- // validate input
- if (empty($ISBN_no)) {
- $ISBN_noError = 'Please enter ISBN number.';
- $valid = false;
- }
- if (empty($book_title)) {
- $book_titleError = 'Please enter book title.';
- $valid = false;
- }
- if (empty($author_name)) {
- $authorError = 'Please enter the author name.';
- $valid = false;
- }
- if (empty($year_published)) {
- $year_publishedError = 'Please enter the year the book was published.';
- $valid = false;
- }
- if (empty($price)) {
- $priceError = 'Please enter price of the book.';
- $valid = false;
- }
- if (empty($publisher)) {
- $publisherError = 'Please enter the name of the publisher.';
- $valid = false;
- }
- if (empty($genre)) {
- $genreError = 'Please enter the type of genre the book is.';
- $valid = false;
- }
- if (empty($image)) {
- $imageError = 'Please insert image of the book.';
- $valid = false;
- }
- // update data
- if ($valid) {
- $pdo = Database::connect();
- $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql = "UPDATE books set ISBN_no = ?, book_title = ?, author_name =?, year_published = ?, price = ?, publisher = ?, genre = ?";
- $q = $pdo->prepare($sql);
- $q->execute(array($ISBN_no,$book_title,$author_name,$year_published,$price,$publisher,$genre));
- Database::disconnect();
- header("Location: adminpage.php");
- }
- } else {
- $pdo = Database::connect();
- $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql = "SELECT * FROM books where id = ?";
- $q = $pdo->prepare($sql);
- $q->execute(array($id));
- $data = $q->fetch(PDO::FETCH_ASSOC);
- $ISBN_no = $data['ISBN_no'];
- $book_title = $data['book_title'];
- $author_name = $data['author_name'];
- $year_published = $data['year_published'];
- $price = $data['price'];
- $publisher = $data['publisher'];
- $genre = $data['genre'];
- Database::disconnect();
- }
- ?>
- <head>
- <meta charset="utf-8">
- <link href="css/bootstrap.min.css" rel="stylesheet">
- <script src="js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container">
- <div class="span10 offset1">
- <div class="row">
- <h3>Update a Book's details</h3>
- </div>
- <form class="form-horizontal" action="update.php?id=<?php echo $id?>" method="post">
- <div class="control-group <?php echo !empty($ISBN_noError)?'error':'';?>">
- <label class="control-label">ISBN Number</label>
- <div class="controls">
- <input name="ISBN_no" type="text" placeholder="ISBN_no" value="<?php echo !empty($ISBN_no)?$ISBN_no:'';?>">
- <?php if (!empty($ISBN_noError)): ?>
- <span class="help-inline"><?php echo $ISBN_noError;?></span>
- <?php endif; ?>
- </div>
- </div>
- <div class="control-group <?php echo !empty($book_titleError)?'error':'';?>">
- <label class="control-label">Title</label>
- <div class="controls">
- <input name="book_title" type="text" placeholder="book_title" value="<?php echo !empty($book_title)?$book_title:'';?>">
- <?php if (!empty($book_titleError)): ?>
- <span class="help-inline"><?php echo $book_titleError;?></span>
- <?php endif;?>
- </div>
- </div>
- <div class="control-group <?php echo !empty($author_nameError)?'error':'';?>">
- <label class="control-label">Author</label>
- <div class="controls">
- <input name="author_name" type="text" placeholder="author_name" value="<?php echo !empty($author_name)?$author_name:'';?>">
- <?php if (!empty($author_nameError)): ?>
- <span class="help-inline"><?php echo $author_nameError;?></span>
- <?php endif;?>
- </div>
- </div>
- <div class="control-group <?php echo !empty($year_publishedError)?'error':'';?>">
- <label class="control-label">Year Pub.</label>
- <div class="controls">
- <input name="year_published" type="text" placeholder="year_published" value="<?php echo !empty($year_published)?$year_published:'';?>">
- <?php if (!empty($author_publishedError)): ?>
- <span class="help-inline"><?php echo $author_publishedError;?></span>
- <?php endif; ?>
- </div>
- </div>
- <div class="control-group <?php echo !empty($priceError)?'error':'';?>">
- <label class="control-label">Price £</label>
- <div class="controls">
- <input name="price" type="text" placeholder="price" value="<?php echo !empty($price)?$price:'';?>">
- <?php if (!empty($priceError)): ?>
- <span class="help-inline"><?php echo $priceError;?></span>
- <?php endif; ?>
- </div>
- </div>
- <div class="control-group <?php echo !empty($publisherError)?'error':'';?>">
- <label class="control-label">Publisher</label>
- <div class="controls">
- <input name="publisher" type="text" placeholder="publisher" value="<?php echo !empty($publisher)?$publisher:'';?>">
- <?php if (!empty($publisherError)): ?>
- <span class="help-inline"><?php echo $publisherError;?></span>
- <?php endif; ?>
- </div>
- </div>
- <div class="control-group <?php echo !empty($genreError)?'error':'';?>">
- <label class="control-label">Genre</label>
- <div class="controls">
- <input name="genre" type="text" placeholder="genre" value="<?php echo !empty($genre)?$genre:'';?>">
- <?php if (!empty($genreError)): ?>
- <span class="help-inline"><?php echo $genreError;?></span>
- <?php endif; ?>
- </div>
- </div>
- <div class="form-actions">
- <button type="submit" class="btn btn-success">Update</button>
- <a class="btn" href="adminpage.php">Back</a>
- </div>
- </form>
- </div>
- </div> <!-- /container -->
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement