From 79aa26cf529ce7df4bb79d611b363523dd0bb799 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Thu, 11 Dec 2025 19:31:10 +0000 Subject: [PATCH] 1.3 --- dashboard.php | 3 +- delete_item.php | 41 +++++++++++++ edit_item.php | 150 ++++++++++++++++++++++++++++++++++++++++++++++++ my_listings.php | 106 ++++++++++++++++++++++++++++++++++ 4 files changed, 299 insertions(+), 1 deletion(-) create mode 100644 delete_item.php create mode 100644 edit_item.php create mode 100644 my_listings.php diff --git a/dashboard.php b/dashboard.php index dced25f..aadeca6 100644 --- a/dashboard.php +++ b/dashboard.php @@ -43,7 +43,8 @@ if ($user_role === 'user') {

Welcome to your RentEase dashboard.

Your role is:

- Add New Item + Add New Item + My Listings
diff --git a/delete_item.php b/delete_item.php new file mode 100644 index 0000000..f6c7734 --- /dev/null +++ b/delete_item.php @@ -0,0 +1,41 @@ +prepare("SELECT id FROM items WHERE id = ? AND owner_id = ?"); + $stmt->execute([$item_id, $vendor_id]); + $item = $stmt->fetch(); + + if ($item) { + // Item belongs to the vendor, proceed with deletion + $stmt = $pdo->prepare("DELETE FROM items WHERE id = ? AND owner_id = ?"); + $stmt->execute([$item_id, $vendor_id]); + + $_SESSION['success_message'] = "Item deleted successfully!"; + } else { + $_SESSION['error_message'] = "Item not found or you don't have permission to delete it."; + } + } catch (PDOException $e) { + $_SESSION['error_message'] = "Database error: " . $e->getMessage(); + } +} else { + $_SESSION['error_message'] = "No item ID provided."; +} + +header("Location: my_listings.php"); +exit(); +?> diff --git a/edit_item.php b/edit_item.php new file mode 100644 index 0000000..5773f4e --- /dev/null +++ b/edit_item.php @@ -0,0 +1,150 @@ +prepare("SELECT * FROM items WHERE id = ? AND owner_id = ?"); + $stmt->execute([$item_id, $vendor_id]); + $item = $stmt->fetch(); + + if (!$item) { + $errors[] = "Item not found or you don't have permission to edit it."; + $item_id = null; // Invalidate item_id if not found or unauthorized + } +} else { + $errors[] = "No item ID provided."; +} + +// Handle form submission for updating the item +if ($_SERVER["REQUEST_METHOD"] == "POST" && $item_id) { + $name = trim($_POST['name']); + $description = trim($_POST['description']); + $price_per_day = trim($_POST['price_per_day']); + $location = trim($_POST['location']); + $image_url = trim($_POST['image_url']); + + if (empty($name)) { + $errors[] = "Item name is required."; + } + if (empty($price_per_day) || !is_numeric($price_per_day)) { + $errors[] = "A valid price is required."; + } + if (empty($location)) { + $errors[] = "Location is required."; + } + + if (empty($errors)) { + try { + $sql = "UPDATE items SET name = :name, description = :description, price_per_day = :price_per_day, location = :location, image_url = :image_url WHERE id = :id AND owner_id = :owner_id"; + $stmt = $pdo->prepare($sql); + $stmt->execute([ + ':name' => $name, + ':description' => $description, + ':price_per_day' => $price_per_day, + ':location' => $location, + ':image_url' => $image_url, + ':id' => $item_id, + ':owner_id' => $vendor_id + ]); + $success_message = "Item updated successfully!"; + // Refresh item data after update + $stmt = $pdo->prepare("SELECT * FROM items WHERE id = ? AND owner_id = ?"); + $stmt->execute([$item_id, $vendor_id]); + $item = $stmt->fetch(); + + } catch (PDOException $e) { + $errors[] = "Database error: " . $e->getMessage(); + } + } +} + +?> + + + + + + Edit Item - RentEase + + + + + + + +
+
+
+
+
+

Edit Rental Item

+
+
+ +
+ +

+ +
+ + +
+ +
+ + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + Cancel +
+ +

Unable to load item for editing.

+ Back to My Listings + +
+
+
+
+
+ + + + + + diff --git a/my_listings.php b/my_listings.php new file mode 100644 index 0000000..50fa0cc --- /dev/null +++ b/my_listings.php @@ -0,0 +1,106 @@ +prepare($query); + $stmt->execute($params); + $items = $stmt->fetchAll(); +?> + + +
+
+
+
+
+

's Listings

+
+
+ +
+ +
+ + +
+ +
+ +

Manage your listed items here.

+ +
+
+ + + +
+
+ + +

You have not listed any items yet. Add a new item.

+ +
+ +
+
+ <?php echo htmlspecialchars($item['name']); ?> +
+
+

+

Price: $ per day

+

Location:

+
+ View + Edit + Delete +

Status:

+
+
+
+
+ +
+ +
+
+
+
+
+ +