D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
markniuj
/
bazmeasar.com
/
Filename :
submit_book.php
back
Copy
<?php // Database connection // Database connection parameters $servername = "localhost"; $username = "markniuj_bazmpbto"; $password = "BC)1at0Y8Wa{"; $dbname = "markniuj_bazmpbto_november-2023"; // Establish a database connection $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $conn->set_charset("utf8mb4"); // Check if form is submitted if ($_SERVER['REQUEST_METHOD'] == 'POST') { $title = $_POST['title']; $author = $_POST['author']; $pdf_link = $_POST['pdf_link']; $description = $_POST['description']; $publish_date = $_POST['publish_date']; // Handle file upload for the thumbnail if (isset($_FILES['thumbnail']) && $_FILES['thumbnail']['error'] === UPLOAD_ERR_OK) { $thumbnail_dir = 'admin/uploads/thumbnails/'; $thumbnail_name = basename($_FILES['thumbnail']['name']); $thumbnail_path = $thumbnail_dir . time() . '_' . $thumbnail_name; // Create the directory if it doesn't exist if (!is_dir($thumbnail_dir)) { mkdir($thumbnail_dir, 0755, true); } // Move uploaded file to the target directory if (move_uploaded_file($_FILES['thumbnail']['tmp_name'], $thumbnail_path)) { // Insert book data into the database with thumbnail path $sql = "INSERT INTO books (title, author, pdf_link, thumbnail, description, publish_date) VALUES (?, ?, ?, ?, ?, ?)"; $stmt = $conn->prepare($sql); $stmt->bind_param('ssssss', $title, $author, $pdf_link, $thumbnail_path, $description, $publish_date); if ($stmt->execute()) { echo "Book added successfully!"; } else { echo "Error: " . $stmt->error; } $stmt->close(); } else { echo "Failed to upload thumbnail."; } } else { echo "Please upload a valid thumbnail image."; } $conn->close(); } ?>