Domain: amberpublishers.in
Server Adress: 86.38.243.169
privdayz.com
<?php
session_start();
require 'include/PHPHelper.php';
if (!isset($_SESSION['userID'])) {
header("location: login.php");
} else {
if (isset($_POST['submit'])) {
// Get the book ID from the form
$bookID = $_POST['book_id'];
// Get the updated book details from the form
$bookName = $_POST['book_name'];
$author = $_POST['author'];
$isbn = $_POST['ISBN'];
$pages = $_POST['Number_of_Pages'];
$price = $_POST['price'];
$language = $_POST['language'];
$publishedDate = $_POST['publisheddate'];
$category = $_POST['category'];
$bookTag = $_POST['book_tag'];
$bookCover = $_FILES['book_cover'];
$bookPDF = $_FILES['book_pdf'];
// Check if a new book cover image was uploaded
if ($bookCover['size'] > 0) {
// Process the uploaded book cover image
// Move the temporary file to the desired location
$targetDirectory = '../assets/img/bookcover/';
$targetFile = $targetDirectory . basename($bookCover['name']);
move_uploaded_file($bookCover['tmp_name'], $targetFile);
// Get only the file name
$bookCoverName = basename($bookCover['name']);
// Update the book cover image path in the database
$sql = "UPDATE book_details SET book_cover=? WHERE id=?";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, "si", $bookCoverName, $bookID);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
}
// Check if a new PDF file was uploaded
if ($bookPDF['size'] > 0) {
// Process the uploaded PDF file
// Move the temporary file to the desired location
$targetDirectory = '../assets/pdf/';
$targetFile = $targetDirectory . basename($bookPDF['name']);
move_uploaded_file($bookPDF['tmp_name'], $targetFile);
// Get only the file name
$bookPDFName = basename($bookPDF['name']);
// Update the book PDF path in the database
$sql = "UPDATE book_details SET book_pdf=? WHERE id=?";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, "si", $bookPDFName, $bookID);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
}
// Update the book details in the database
$sql = "UPDATE book_details SET title=?, author=?, ISBN=?, Number_of_Pages=?, Price=?, language=?, publishedyear=?, category=?, book_tag=? WHERE id=?";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, "ssssdssssi", $bookName, $author, $isbn, $pages, $price, $language, $publishedDate, $category, $bookTag, $bookID);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
// Redirect to the page displaying all book details
header("Location: editbook.php");
exit();
} else {
// Retrieve the book details from the database based on the ID
$bookID = $_GET['id'];
$query = "SELECT * FROM book_details WHERE id = ?";
$stmt = mysqli_prepare($conn, $query);
mysqli_stmt_bind_param($stmt, "i", $bookID);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$book = mysqli_fetch_assoc($result);
mysqli_stmt_close($stmt);
mysqli_close($conn);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<?php
$title = "Update Book || Amber Publishers";
include 'include/head.php';
?>
<body>
<!-- ======= Header ======= -->
<?php include 'include/header.php'; ?>
<!-- End Header -->
<!-- ======= Sidebar ======= -->
<?php include 'include/sidebar.php'; ?>
<!-- End Sidebar -->
<main id="main" class="main">
<div class="pagetitle">
<h1>Update Book</h1>
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="index.php">IJSRI Dashboard</a></li>
<li class="breadcrumb-item"><a href="editbook.php">Edit Books Details</a></li>
<li class="breadcrumb-item active">Update Book</li>
</ol>
</nav>
</div><!-- End Page Title -->
<section class="section">
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<div class="card-title">
<h5>Update Book</h5>
<div class="form">
<form method="POST" action="updatebook.php" enctype="multipart/form-data">
<!-- Rest of the form fields remain the same -->
<div class="row mb-3">
<label for="book_name" class="col-md-4 col-lg-3 col-form-label">Book Name:</label>
<div class="col-md-8 col-lg-9">
<input type="text" class="form-control" name="book_name" id="book_name" value="<?php echo $book['title']; ?>" required>
</div>
</div>
<div class="row mb-3">
<label for="author" class="col-md-4 col-lg-3 col-form-label">Author:</label>
<div class="col-md-8 col-lg-9">
<input type="text" class="form-control" name="author" id="author" value="<?php echo $book['author']; ?>" required>
</div>
</div>
<div class="row mb-3">
<label for="ISBN" class="col-md-4 col-lg-3 col-form-label">ISBN</label>
<div class="col-md-8 col-lg-9">
<input name="ISBN" type="text" class="form-control" id="ISBN" value="<?php echo $book['ISBN']; ?>" placeholder="Enter ISBN Number">
</div>
</div>
<div class="row mb-3">
<label for="Number_of_Pages" class="col-md-4 col-lg-3 col-form-label">Number of Pages</label>
<div class="col-md-8 col-lg-9">
<input name="Number of Pages" type="text" class="form-control" value="<?php echo $book['Number_of_Pages']; ?>" id="Number of Pages" placeholder="Enter Number of Pages">
</div>
</div>
<div class="row mb-3">
<label for="price" class="col-md-4 col-lg-3 col-form-label">Price:</label>
<div class="col-md-8 col-lg-9">
<input type="text" class="form-control" name="price" id="price" value="<?php echo $book['Price']; ?>" required>
</div>
</div>
<div class="row mb-3">
<label for="language" class="col-md-4 col-lg-3 col-form-label">Language</label>
<div class="col-md-8 col-lg-9">
<select name="language" id="language" class="form-select">
<option value="<?php echo $book['language']; ?>"><?php echo $book['language']; ?></option>
<option value="English">English </option>
<option value="Bengali">Bengali</option>
<option value="Gujarati">Gujarati</option>
<option value="Hindi">Hindi</option>
<option value="Sanskrit">Sanskrit</option>
<option value="Urdu">Urdu</option>
<option value="other">Other</option>
</select>
</div>
</div>
<div class="row mb-3">
<label for="publisheddate" class="col-md-4 col-lg-3 col-form-label">Published Date</label>
<div class="col-md-8 col-lg-9">
<input type="date" name="publisheddate" value="<?php echo $book['publishedyear']; ?>" id="publisheddate" class="form-control">
</div>
</div>
<div class="row mb-3">
<label for="category" class="col-md-4 col-lg-3 col-form-label" value="<?php echo $book['category']; ?>">Category</label>
<div class="col-md-8 col-lg-9">
<select name="category" id="category" class="form-select">
<option value="<?php echo $book['category']; ?>"><?php echo $book['category']; ?></option>
<option value="Science & Technology">Science & Technology</option>
<option value="Philosophy">Philosophy</option>
<option value="Social Sciences">Social Sciences</option>
<option value="Literature">Literature</option>
<option value="Arts">Arts</option>
<option value="Educational Book">Educational Book</option>
<option value="Ideology">Ideology</option>
<option value="Edited Book">Edited Book</option>
<option value="Conference Proceeding">Conference Proceeding</option>
<option value="School Children Book">School Children Book</option>
<option value="Thesis/Dissertation">Thesis/Dissertation</option>
<option value="Others">Others</option>
</select>
</div>
</div>
<div class="row mb-3">
<label for="book_tag" class="col-md-4 col-lg-3 col-form-label">Book Tag</label>
<div class="col-md-8 col-lg-9">
<select name="book_tag" id="book_tag" class="form-select">
<option value="<?php echo $book['book_tag']; ?>"><?php echo $book['book_tag']; ?></option>
<option value="Recent">Recent</option>
<option value="Editedvolu">Edited Volume</option>
<option value="Upcoming">Up coming</option>
</select>
</div>
</div>
<div class="row mb-3">
<label for="book-cover" class="col-md-4 col-lg-3 col-form-label">Book Cover Image</label>
<div class="col-md-8 col-lg-9">
<input type="file" name="book_cover" id="book_cover" accept="image/png, image/jpeg, image/jpg" class="form-control">
<p class="form-text">Upload a new photograph if you want to update it.</p>
</div>
</div>
<div class="row mb-3">
<label for="book_pdf" class="col-md-4 col-lg-3 col-form-label">Book PDF</label>
<div class="col-md-8 col-lg-9">
<input type="file" name="book_pdf" id="book_pdf" accept="application/pdf" class="form-control">
<p class="form-text">Upload a new PDF file if you want to update it.</p>
</div>
</div>
<input type="hidden" name="book_id" value="<?php echo $book['id']; ?>">
<div class="row mt-3">
<div class="text-center">
<input type="submit" name="submit" id="submit" class="btn btn-primary col-lg-12" value="Update Book Details">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</main><!-- End #main -->
<!-- ======= Footer ======= -->
<?php include 'include/footer.php'; ?>
</body>
</html>
