Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325
prepare("SELECT * FROM books WHERE id = ?"); $stmt->bind_param("i", $id); $stmt->execute(); $result = $stmt->get_result(); if ($result && $result->num_rows > 0) { $row = $result->fetch_assoc(); } else { $stmt->close(); $conn->close(); header("Location: AddBook.php"); exit; } $stmt->close(); // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST') { $book_title = trim($_POST['book_title']); $book_price = trim($_POST['book_price']); $book_image = $row['book_image']; // Keep existing image by default // Validate inputs if (empty($book_title)) { $error = "Book title is required."; } elseif (!is_numeric($book_price) || $book_price < 0) { $error = "Invalid book price."; } // Handle new image upload if (empty($error) && isset($_FILES['book_image']) && $_FILES['book_image']['error'] === 0) { $allowed_types = ['image/jpeg', 'image/png', 'image/gif', 'image/webp']; $file_type = $_FILES['book_image']['type']; if (!in_array($file_type, $allowed_types)) { $error = "Invalid file type. Only JPG, PNG, GIF, and WEBP are allowed."; } elseif ($_FILES['book_image']['size'] > 5000000) { // 5MB limit $error = "File size must be less than 5MB."; } else { // Delete old image file $old_image_path = str_replace('images/books/', '', $row['book_image']); $old_file = __DIR__ . '/../../images/books/' . $old_image_path; if (file_exists($old_file)) { unlink($old_file); } // Upload new image $file_extension = pathinfo($_FILES['book_image']['name'], PATHINFO_EXTENSION); $book_image = uniqid('book_', true) . '.' . $file_extension; $target_dir = __DIR__ . '/../../images/books/'; if (!is_dir($target_dir)) { mkdir($target_dir, 0755, true); } $target_file = $target_dir . $book_image; if (!move_uploaded_file($_FILES['book_image']['tmp_name'], $target_file)) { $error = "Failed to upload new image."; } } } // Update database if no errors if (empty($error)) { $stmt = $conn->prepare("UPDATE books SET book_title = ?, book_image = ?, book_price = ? WHERE id = ?"); if ($stmt) { $stmt->bind_param("ssdi", $book_title, $book_image, $book_price, $id); if ($stmt->execute()) { $stmt->close(); $conn->close(); // Redirect to listing page with success message header("Location: AddBook.php?updated=1"); exit; } else { $error = "Failed to update book: " . $stmt->error; } $stmt->close(); } else { $error = "Failed to prepare statement: " . $conn->error; } } } // Clean image path for display $displayImagePath = str_replace('images/books/', '', $row['book_image']); $fullImagePath = __DIR__ . '/../../images/books/' . $displayImagePath; // Add cache busting parameter $cacheBuster = file_exists($fullImagePath) ? '?v=' . filemtime($fullImagePath) : ''; ?> Edit Book - <?php echo htmlspecialchars($row['book_title']); ?>
Back to Book List

Edit Book

Current Image
<?php echo htmlspecialchars($row['book_title']); ?>
📚
Leave empty to keep current image. Max size: 5MB
Cancel
close(); ?>