Properties Management
Add and oversee active real estate listings
| Image | Property Details | Type & Badges | Specs (Beds/Baths/Sqft) | Price | Action |
|---|---|---|---|---|---|
| No properties found. Click "Add New Property" to start. | |||||
// 2. HANDLE ADD PROPERTY SUBMISSION if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_property'])) { $title = trim($_POST['title']); $type = trim($_POST['type']); $location = trim($_POST['location']); $price = trim($_POST['price']); $installment_3_months_price = !empty($_POST['installment_3_months_price']) ? trim($_POST['installment_3_months_price']) : $price; $installment_12_months_price = !empty($_POST['installment_12_months_price']) ? trim($_POST['installment_12_months_price']) : $price; $outright_price = !empty($_POST['outright_price']) ? trim($_POST['outright_price']) : $price; $price_suffix = trim($_POST['price_suffix'] ?? ''); $badge_1 = trim($_POST['badge_1'] ?? 'For Sale'); $badge_2 = trim($_POST['badge_2']); $beds = intval($_POST['beds']); $baths = intval($_POST['baths']); $sqft = trim($_POST['sqft']); $garage = trim($_POST['garage']); // Handle Image Upload $imagePath = ''; if (isset($_FILES['property_image']) && $_FILES['property_image']['error'] === UPLOAD_ERR_OK) { $fileTmpPath = $_FILES['property_image']['tmp_name']; $fileName = $_FILES['property_image']['name']; $fileSize = $_FILES['property_image']['size']; $fileExtension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); $allowedExtensions = ['jpg', 'jpeg', 'png', 'webp']; if (in_array($fileExtension, $allowedExtensions) && $fileSize <= (5 * 1024 * 1024)) { $uploadDir = '../uploads/properties/'; if (!is_dir($uploadDir)) { mkdir($uploadDir, 0755, true); } $newFileName = 'prop_' . time() . '.' . $fileExtension; $destPath = $uploadDir . $newFileName; if (move_uploaded_file($fileTmpPath, $destPath)) { $imagePath = 'uploads/properties/' . $newFileName; } } } if (!empty($title) && !empty($imagePath)) { try { $stmt = $pdo->prepare("INSERT INTO properties (title, type, location, price, price_suffix, installment_3_months_price, installment_12_months_price, outright_price, badge_1, badge_2, beds, baths, sqft, garage, image) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([$title, $type, $location, $price, $price_suffix, $installment_3_months_price, $installment_12_months_price, $outright_price, $badge_1, $badge_2, $beds, $baths, $sqft, $garage, $imagePath]); $_SESSION['toast_success'] = "Property added successfully!"; header("Location: properties.php"); exit(); } catch (PDOException $e) { $_SESSION['toast_error'] = "Database error: Failed to add property."; } } else { $_SESSION['toast_error'] = "Please provide a valid title and property image."; } } // 3. HANDLE DELETE PROPERTY if (isset($_GET['delete'])) { $id = intval($_GET['delete']); try { $stmt = $pdo->prepare("SELECT image FROM properties WHERE id = ?"); $stmt->execute([$id]); $img = $stmt->fetchColumn(); if ($img && file_exists('../' . $img)) { unlink('../' . $img); } $pdo->prepare("DELETE FROM properties WHERE id = ?")->execute([$id]); $_SESSION['toast_success'] = "Property deleted successfully."; header("Location: properties.php"); exit(); } catch (PDOException $e) { $_SESSION['toast_error'] = "Failed to delete property."; } } // 4. FETCH PROPERTIES $properties = []; try { $stmt = $pdo->query("SELECT * FROM properties ORDER BY created_at DESC"); $properties = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) {} ?>
Add and oversee active real estate listings
| Image | Property Details | Type & Badges | Specs (Beds/Baths/Sqft) | Price | Action |
|---|---|---|---|---|---|
| No properties found. Click "Add New Property" to start. | |||||