D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
u193541357
/
domains
/
racysanitaryware.com
/
public_html
/
admin
/
Filename :
add-icon.php
back
Copy
<?php include('header.php'); ?> <?php // Variables for storing icon details $id = ''; $icon_name = ''; $icon_image = ''; // Initialize as empty (for new icons) $status = 1; // Default to active status // Check if updating an existing icon if (isset($_GET['id'])) { $id = $_GET['id']; $sql = "SELECT * FROM icons WHERE id = ?"; $stmt = $conn->prepare($sql); $stmt->bind_param('i', $id); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { $row = $result->fetch_assoc(); $icon_name = $row['icon_name']; $icon_image = $row['icon_image']; // Existing image URL or path $status = $row['status']; // This will be fetched from the database } } ?> <div class="container-fluid"> <div class="d-sm-flex align-items-center justify-content-between mb-4"> <h1 class="h3 mb-0 text-gray-800"><?php echo isset($id) ? 'Update Icon' : 'Add Icon'; ?></h1> </div> <div class="card shadow mb-4"> <div class="card-body"> <form class="user" id="icon-form" method="post" action="submit-icon.php" enctype="multipart/form-data"> <input type="hidden" name="id" value="<?php echo $id; ?>"> <!-- Hidden ID for update --> <div class="form-group row"> <div class="col-sm-6 mb-3"> <label for="icon_name">Icon Name</label> <input type="text" class="form-control form-control-user" id="icon_name" placeholder="Enter Icon Name" name="icon_name" value="<?php echo $icon_name; ?>" required> </div> <div class="col-sm-6 mb-3"> <label for="icon_image">Icon Image (Upload)</label> <input type="file" class="form-control form-control-user form-control-file" id="icon_image" name="icon_image" accept="image/*" <?php echo !empty($id) ? '' : 'required'; ?>> </div> <div class="col-sm-12 mb-3"> <label for="icon_image_preview">Icon Image Preview</label> <div class="position-relative mt-2 preview" id="iconImagePreview"> <?php if (!empty($icon_image)) : ?> <img src="<?php echo $icon_image; ?>" alt="Icon Image" style="max-width: 120px; margin-top:10px;"> <?php else : ?> <img src="" alt="" style="max-width: 120px; margin-top:10px; display: none;"> <?php endif; ?> </div> </div> </div> <button type="submit" class="btn btn-primary btn-user btn-block"> <?php echo (!isset($id) || empty($id)) ? 'Add Icon' : 'Update Icon'; ?> </button> </form> </div> </div> </div> <script> // Optionally, you can add image preview for file upload document.getElementById('icon_image').addEventListener('change', function(event) { const preview = document.getElementById('iconImagePreview'); const reader = new FileReader(); reader.onload = function() { const img = new Image(); img.src = reader.result; img.style.maxWidth = '120px'; preview.innerHTML = ''; // Clear the current preview preview.appendChild(img); // Show the new image }; reader.readAsDataURL(event.target.files[0]); }); </script> <?php include('footer.php'); ?>