D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
public_html
/
encoadminders
/
Filename :
edit_gallery.php
back
Copy
<?php session_start(); include 'config.php'; if (!isset($_SESSION['admin_name'])) { echo '<script>window.location.href = "login.php";</script>'; exit; } if (isset($_GET['id'])) { $id = mysqli_real_escape_string($conn, $_GET['id']); // Fetch the existing gallery item data $sql = "SELECT * FROM gallery WHERE gallery_id = '$id'"; $result = mysqli_query($conn, $sql); $gallery = mysqli_fetch_assoc($result); if (!$gallery) { echo "Gallery item not found."; exit; } } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $category = mysqli_real_escape_string($conn, $_POST['category']); $title = mysqli_real_escape_string($conn, $_POST['title']); $image_name = $gallery['image']; // keep the existing image by default // Check if a new image is uploaded if (isset($_FILES['image']['name']) && $_FILES['image']['name'] != '') { $image_name = time() . '_' . $_FILES['image']['name']; $upload_dir = 'uploads/gallery/'; $upload_file = $upload_dir . basename($image_name); // Check if upload directory exists if (!file_exists($upload_dir)) { mkdir($upload_dir, 0777, true); } // Move the uploaded file if (!move_uploaded_file($_FILES['image']['tmp_name'], $upload_file)) { $error = "Error uploading the image."; } } // Update the gallery item in the database if (!isset($error)) { $sql = "UPDATE gallery SET category = '$category', title = '$title', image = '$image_name' WHERE gallery_id = '$id'"; if (mysqli_query($conn, $sql)) { $success = "Gallery image updated successfully."; } else { $error = "Database error: " . mysqli_error($conn); } } } ?> <!DOCTYPE html> <html lang="en"> <head> <?php require('style.php'); ?> <title>Edit Gallery Image</title> <style> @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap'); body { background: linear-gradient(120deg, #6a11cb, #2575fc); font-family: 'Poppins', sans-serif; margin: 0; padding: 0; display: flex; align-items: center; justify-content: center; min-height: 100vh; } .container { max-width: 500px; width: 100%; background: #fff; border-radius: 15px; padding: 25px 30px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2); position: relative; } .container h1 { text-align: center; font-size: 24px; font-weight: 600; color: #444; margin-bottom: 25px; } .form-group { margin-bottom: 20px; } .form-group label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 8px; color: #555; } .form-control { width: 100%; height: 45px; border: 1px solid #ddd; border-radius: 8px; padding: 0 15px; font-size: 14px; color: #555; outline: none; transition: border 0.3s; } .form-control:focus { border: 1px solid #2575fc; } .form-group input[type="file"] { padding: 5px; } .btn-primary { width: 100%; height: 45px; background: linear-gradient(90deg, #6a11cb, #2575fc); border: none; border-radius: 8px; color: #fff; font-size: 16px; font-weight: 600; cursor: pointer; transition: transform 0.3s, box-shadow 0.3s; } .btn-primary:hover { transform: translateY(-3px); box-shadow: 0 8px 15px rgba(106, 17, 203, 0.3); } .alert { padding: 12px; border-radius: 8px; margin-bottom: 15px; font-size: 14px; } .alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; } .alert-danger { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; } .form-container { animation: fadeInUp 0.8s ease-in-out; } @keyframes fadeInUp { 0% { opacity: 0; transform: translateY(20px); } 100% { opacity: 1; transform: translateY(0); } } </style> </head> <body> <?php include('sidebar.php') ?> <div class="home-section"> <div class="container form-container"> <h1>Edit Gallery Image</h1> <?php if (isset($success)) : ?> <div class="alert alert-success"><?= $success ?></div> <?php endif; ?> <?php if (isset($error)) : ?> <div class="alert alert-danger"><?= $error ?></div> <?php endif; ?> <form action="" method="POST" enctype="multipart/form-data"> <div class="form-group"> <label for="title">Image Title</label> <input type="text" name="title" id="title" class="form-control" value="<?= $gallery['title'] ?>" required> </div> <div class="form-group"> <label for="category">Category</label> <select name="category" id="category" class="form-control" required> <option value="Sikkim" <?= ($gallery['category'] == 'Sikkim') ? 'selected' : '' ?>>Sikkim</option> <option value="Office" <?= ($gallery['category'] == 'Office') ? 'selected' : '' ?>>Office</option> <option value="Digital" <?= ($gallery['category'] == 'Digital') ? 'selected' : '' ?>>Digital</option> </select> </div> <div class="form-group"> <label for="image">Image</label> <input type="file" name="image" id="image" class="form-control" accept="image/*"> <small>Current Image: <img src="uploads/gallery/<?= $gallery['image'] ?>" width="100" alt="current image"></small> </div> <button type="submit" class="btn-primary">Update Image</button> </form> </div> <?php include('footer.php') ?> </div> </body> </html>