D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
u193541357
/
domains
/
racysanitaryware.com
/
public_html
/
1
/
admin
/
Filename :
submit-icon.php
back
Copy
<?php include('../db.php'); // Include database connection if ($_SERVER["REQUEST_METHOD"] == "POST") { $id = isset($_POST['id']) ? $_POST['id'] : ''; // Get the icon ID for update $icon_name = $conn->real_escape_string($_POST['icon_name']); // Escape input for security $status = 1; // Default status // Directory for storing icon images $baseDir = "img/icons/"; // Create the directory if it doesn't exist if (!is_dir($baseDir)) { mkdir($baseDir, 0777, true); } // Handle icon image upload $icon_image = ''; if (isset($_FILES['icon_image']) && $_FILES['icon_image']['error'] === UPLOAD_ERR_OK) { $fileName = basename($_FILES['icon_image']['name']); $targetFilePath = $baseDir . time() . "_" . $fileName; if (move_uploaded_file($_FILES['icon_image']['tmp_name'], $targetFilePath)) { $icon_image = $targetFilePath; } else { die("Error uploading icon image."); } } // If updating, fetch the existing image path if no new image is uploaded if (!empty($id)) { $sql = "SELECT icon_image FROM icons WHERE id = ?"; $stmt = $conn->prepare($sql); $stmt->bind_param('i', $id); $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_assoc(); if (empty($icon_image)) $icon_image = $row['icon_image']; // Retain old image if no new one uploaded $stmt->close(); } // Insert or update icon data if (!empty($id)) { // Update existing icon $sql = "UPDATE icons SET icon_name = ?, icon_image = ?, status = ? WHERE id = ?"; $stmt = $conn->prepare($sql); $stmt->bind_param('ssii', $icon_name, $icon_image, $status, $id); if ($stmt->execute()) { echo "Icon updated successfully!"; } else { echo "Error updating icon: " . $stmt->error; } } else { // Insert new icon $sql = "INSERT INTO icons (icon_name, icon_image, status) VALUES (?, ?, ?)"; $stmt = $conn->prepare($sql); $stmt->bind_param('ssi', $icon_name, $icon_image, $status); if ($stmt->execute()) { echo "Icon added successfully!"; } else { echo "Error adding icon: " . $stmt->error; } } $stmt->close(); $conn->close(); // Redirect to view icons page header("Location: view-icon.php"); exit(); } ?>