D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
sg.encodersunlimited.com
/
sgadminpr
/
Filename :
edit-category.php
back
Copy
<?php include 'config.php'; $id = $_GET['id'] ?? 0; $id = intval($id); $stmt = $conn->prepare("SELECT * FROM categories WHERE id = ?"); $stmt->bind_param("i", $id); $stmt->execute(); $result = $stmt->get_result(); if (!$result || $result->num_rows === 0) { die("Category not found!"); } $row = $result->fetch_assoc(); $stmt->close(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $category_name = $_POST['category_name']; $category_desc = $_POST['category_desc']; $category_type = $_POST['category_type']; $stmt = $conn->prepare("UPDATE categories SET category_name = ?, category_desc = ?, category_type = ?, updated_at = NOW() WHERE id = ?"); $stmt->bind_param("sssi", $category_name, $category_desc, $category_type, $id); if ($stmt->execute()) { echo "<script>alert('Category updated successfully!'); window.location.href='show-category.php';</script>"; } else { echo "Update failed: " . $stmt->error; } $stmt->close(); } ?> <!-- HTML Below --> <!doctype html> <html lang="en"> <head> <title>Edit Category</title> <?php include('../style2.php'); ?> </head> <body> <div class="dashboard__page--wrapper"> <?php include('sidebar.php'); ?> <div class="page__body--wrapper" id="dashbody__page--body__wrapper"> <main class="main__content_wrapper"> <div class="dashboard__container add__property--container"> <div class="add__property--heading mb-30"> <h2 class="add__property--heading__title">Edit Category</h2> </div> <div class="add__property__inner d-flex"> <div class="add__property--step__inner"> <div class="add__property--box mb-30"> <form class="add__property--form" method="POST"> <div class="row"> <div class="col-12 mb-20"> <label class="add__listing--input__label">Category</label> <input type="text" name="category_name" value="<?= htmlspecialchars($row['category_name']); ?>" class="add__listing--input__field" required> </div> <div class="col-12 mb-20"> <label class="add__listing--input__label">Description</label> <textarea name="category_desc" class="add__listing--textarea__field"><?= htmlspecialchars($row['category_desc']); ?></textarea> </div> <div class="col-12 mb-20"> <label class="add__listing--input__label">Type</label> <select name="category_type" class="add__listing--form__select"> <?php $types = ["Real Estate", "Flat", "Hotel", "Resort", "Homestay", "Rent"]; foreach ($types as $type) { $selected = ($row['category_type'] === $type) ? "selected" : ""; echo "<option value=\"$type\" $selected>$type</option>"; } ?> </select> </div> <div class="col-12"> <button type="submit" class="btn btn-primary">Update Category</button> </div> </div> </form> </div> </div> </div> </div> </main> </div> </div> <?php include 'footer.php'; ?> </body> </html>